PDA

View Full Version : I2CRead problem



Ioannis
- 17th October 2018, 22:44
Very strange problem.

Executing an I2CRead command does only I2CWrite as it is shown on the Logic capture.

This is my test code for an 24C64 EEPROM



DEFINE I2C_SLOW 1
b1 var byte
b2 var byte
addr VAR word
cont CON %10100000
data_pin var porte.0
clk_pin var porte.1

addr = 0
' Read data at address 0 into B1,B2
I2CREAD data_pin,clk_pin,cont,addr,[b1,b2]
stop


Any ideas?

Ioannis

richard
- 18th October 2018, 00:34
can we see the whole transaction , an i2c read needs to do a write to set address and then a restart to read . you have not shown enough

Ioannis
- 18th October 2018, 13:35
Thank you Richard. Will do that this evening.

I tried byte read, word read, page read, Nothing works and all var's are just a zero.

The chip is a 16F1939 but I am sure this does not matter. Logic analyzer shows I2C activity either way.

Edit:

OK, now that is weird. On a 45K22 works just fine. On 1939 not...

Ioannis

Ioannis
- 18th October 2018, 14:31
I am very embarrassed...

I forgot completely ANSELD and ANSELE when testing it...

Ioannis

richard
- 19th October 2018, 14:17
I forgot completely ANSELD


Another good reason to migrate to xc8 , mcc gives all pin settings/names and function in one easy to use screen

Ioannis
- 19th October 2018, 14:57
It is not easy to me. I detest C lanquage. Despite my efforts so far, I did not managed to flip over.

It looks very cryptic...

Ioannis

sayzer
- 19th October 2018, 15:18
Using ready-to-use tools to adjust the registers as we need, kills our ability of playing with them, and lowers the understanding of the hardware registers.

Manual setting as much as possible is a good way of self developing, I think.

richard
- 20th October 2018, 04:24
Using ready-to-use tools to adjust the registers as we need, kills our ability of playing with them, and lowers the understanding of the hardware registers.


setting pin function is pic 101 stuff , but essential to get correct .not much programming skill in there once a basic understanding is reached


Manual setting as much as possible is a good way of self developing, I think.


would you not use dt_ints or PicMultiCalc
if there's a good tool use it ,I think

Ioannis
- 20th October 2018, 13:28
Fuses and the like are a pain. So many new options on the recent chips. I hate it as I loose too much time from the programming itself, on figuring out how to set up a new (or older) chip.

All these settings are getting more and more complex. A tool such as MCC is great but needs C understanding I suppose. Or maybe to that extend to get the fuses and then return to PBP?

Ioannis

richard
- 20th October 2018, 14:07
the mcc generated pin file can very easily slot into pbp
just cut out the comments and the c bits you don't need load replace all the 0x with $


/**
Generated Pin Manager File
 
Company:
Microchip Technology Inc.
 
File Name:
pin_manager.c
 
Summary:
This is the Pin Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
 
Description:
This header file provides implementations for pin APIs for all pins selected in the GUI.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.65.2
Device : PIC18F26K42
Driver Version : 2.01
The generated drivers are tested against the following:
Compiler : XC8 1.45
MPLAB : MPLAB X 4.15
 
Copyright (c) 2013 - 2015 released Microchip Technology Inc. All rights reserved.
*/
 
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.

Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.

THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
FOR A PARTICULAR PURPOSE.

IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
SOFTWARE.
*/
 
#include <xc.h>
#include "pin_manager.h"
#include "stdbool.h"
 
 
 
 
 
void PIN_MANAGER_Initialize(void)
{
/**
LATx registers
*/
LATA = 0x00;
LATB = 0x01;
LATC = 0x02;
 
/**
TRISx registers
*/
TRISA = 0xFF;
TRISB = 0xFC;
TRISC = 0x41;
 
/**
ANSELx registers
*/
ANSELC = 0x01;
ANSELB = 0xF0;
ANSELA = 0xFF;
 
/**
WPUx registers
*/
WPUE = 0x00;
WPUB = 0x00;
WPUA = 0x00;
WPUC = 0x00;
 
/**
ODx registers
*/
ODCONA = 0x00;
ODCONB = 0x00;
ODCONC = 0x00;
 
 
 
 
 



SPI1SDIPPSbits.SPI1SDIPPS = 0x16; //RC6->SPI1:SDI1;
RC4PPS = 0x1E; //RC4->SPI1:SCK1;
SPI1SCKPPSbits.SPI1SCKPPS = 0x14; //RC4->SPI1:SCK1;
RC5PPS = 0x1F; //RC5->SPI1:SDO1;
}

void PIN_MANAGER_IOC(void)
{
}
 
/**
End of File
*/