|
|
View previous topic :: View next topic |
Author |
Message |
SubhamayS
Joined: 07 Mar 2012 Posts: 34 Location: jalpaiguri, India
|
PIC18F2550 eeprom 24LC32A interfacing problem |
Posted: Fri Jul 07, 2017 2:49 am |
|
|
I am trying to interface Microchip 24LC32A EEPROM with PIC18F2550. I am using the driver provided by CCS (2432.c).
Compiler version 5.015
I have used PIN_B2, PIN_B3, PIN_B4 for checking the execution of the code. But only PIN_B2 goes high as I check the code in hardware.
The LCD, RS232 part of the codes are working fine. I have connected two 10k pullup resistors to SDA & SCL lines & WP connected to GND. As shown here https://www.ccsinfo.com/forum/viewtopic.php?t=30393
Code: | #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#define EEPROM_SDA PIN_B0
#define EEPROM_SCL PIN_B1
#include <2432.c>
//=====================================
void main()
{
//================================
lcd_init(); // Turn LCD ON, along with other initialization commands
delay_ms(50);
lcd_gotoxy(1,1); // point LCD cursor to col1 row1
delay_ms(10);
lcd_putc("\f");
printf(lcd_putc,"EEPROM DEMO\n"); // print on LCD
delay_ms(1000);
//================================
init_ext_eeprom(); // to initialize EEPROM
output_high(PIN_B2);
write_ext_eeprom(0, 55);
delay_ms(10);
output_high(PIN_B3);
write_ext_eeprom(2, 85);
delay_ms(10);
output_high(PIN_B4);
printf(lcd_putc,"data@0 %d", read_ext_eeprom(0));
delay_ms(50);
lcd_gotoxy(9,1);
printf(lcd_putc,"data@2 %d", read_ext_eeprom(2));
delay_ms(50);
while(1);
} |
The 2432.c driver I am using is given below:
Code: | #ifndef EEPROM_SDA
#define EEPROM_SDA PIN_C4
#define EEPROM_SCL PIN_C3
#endif
#define hi(x) (*((int8 *)&x+1))
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)
#define EEPROM_ADDRESS long int
#define EEPROM_SIZE 4096
void init_ext_eeprom() {
output_float(EEPROM_SCL);
output_float(EEPROM_SDA);
}
BOOLEAN ext_eeprom_ready() {
int1 ack;
i2c_start(); // If the write command is acknowledged,
ack = i2c_write(0xa0); // then the device is ready.
i2c_stop();
return !ack;
}
void write_ext_eeprom(long int address, BYTE data) {
while(!ext_eeprom_ready());
i2c_start();
i2c_write(0xa0);
i2c_write(hi(address));
i2c_write(address);
i2c_write(data);
i2c_stop();
}
BYTE read_ext_eeprom(long int address) {
BYTE data;
while(!ext_eeprom_ready());
i2c_start();
i2c_write(0xa0);
i2c_write(hi(address));
i2c_write(address);
i2c_start();
i2c_write(0xa1);
data=i2c_read(0);
i2c_stop();
return(data);
}
|
Please Help. I am unable to identify the fault in the code. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 07, 2017 3:13 am |
|
|
You say you never get led B3 to light up. So it's probably locking up
in this routine:
Code: | write_ext_eeprom(0, 55); |
So, you can move the lines for leds B3 and B4 to troubleshoot that routine
in the 2432.c driver. Example:
Code: | void write_ext_eeprom(long int address, BYTE data) {
output_high(PIN_B3);
while(!ext_eeprom_ready());
output_high(PIN_B4);
i2c_start();
i2c_write(0xa0);
i2c_write(hi(address));
i2c_write(address);
i2c_write(data);
i2c_stop();
}
|
My guess is it will light up leds B2 and B3, but led B4 will not light.
At that point, you should start closely looking at your connections
and resistor values. |
|
|
SubhamayS
Joined: 07 Mar 2012 Posts: 34 Location: jalpaiguri, India
|
|
Posted: Fri Jul 07, 2017 4:00 am |
|
|
PCM programmer wrote: | My guess is it will light up leds B2 and B3, but led B4 will not light.
At that point, you should start closely looking at your connections
and resistor values. |
You are right. I tried to test as per your advice. I have added the lines to 2432.c.
LED at B3 lights up but LED at PIN_B4 does not glow.
I have checked the connections everything is ok. due to 10k pull up resistor the
potential at (EEPROM pins) SDA & SCL is 4.72 Volts. I have connected SDA to PIN_B0 to SDA & PIN_B1 to SCL. is it an issue with the 10k resistor ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Jul 07, 2017 5:13 am |
|
|
I suggest replacing the 10K pullups with 4K7. I'm currently bench testing a product that has both the 24LC32 and a DS3231 RTC and the pullups are 4K7. Just measured with DVM, yeesh SMT Rs are small !
I know the driver does work though I did add extensions for both page write (32 bytes) as well as fast erase (128 page mode erases).
I also suggest you download and run the I2C Scanner program from the code library (3-4 posts down...). It makes I2C troubleshooting EASY ! It DOES finds any device on the I2C bus. Just be sure to code the correct I/O pins ! In my case I'm using an 18F46K22 which has 2 I2C busses and needed to code for BOTH busses......
Also as already stated, be sure to check the connections again.
Jay |
|
|
SubhamayS
Joined: 07 Mar 2012 Posts: 34 Location: jalpaiguri, India
|
|
Posted: Fri Jul 07, 2017 6:06 am |
|
|
I have used the 4.7 k resistors this time and tried the I2C Scanner code. it returned:
Code: |
Start:
Nothing Found |
This is the code I have used (from code library):
Code: | #use i2c(Master, sda=PIN_B0, scl=PIN_B1)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
// This function writes the slave address to the i2c bus.
// If a slave chip is at that address, it should respond to
// this with an "ACK". This function returns TRUE if an
// ACK was found. Otherwise it returns FALSE.
int8 get_ack_status(int8 address)
{
int8 status;
i2c_start();
status = i2c_write(address); // Status = 0 if got an ACK
i2c_stop();
if(status == 0)
return(TRUE);
else
return(FALSE);
}
//=================================
void main()
{
unsigned int8 i;
unsigned int8 status;
unsigned int8 count = 0;
printf("\n\rStart:\n\r");
delay_ms(1000);
// Try all slave addresses from 0x10 to 0xEF.
// See if we get a response from any slaves
// that may be on the i2c bus.
for(i=0x10; i < 0xF0; i+=2)
{
status = get_ack_status(i);
if(status == TRUE)
{
printf("ACK addr: %X\n\r", i);
count++;
delay_ms(2000);
}
}
if(count == 0)
printf("\n\rNothing Found");
else
printf("\n\rNumber of i2c chips found: %u", count);
while(1);
} |
Pin: 1,2,3,4 of EEPROM connected to GND,
PIN- 8 to VCC (+5V),
PIN- 7 (WP) TO GND,
PIN- 5 (SDA) to PIN_B0
PIN- 6 (SDA) to PIN_B1
still not working.. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Jul 07, 2017 10:00 am |
|
|
OK, since the Scanner program didn't find it, I suspect a wiring error. I KNOW the Scanner works 100%!
While you mention WP, I just downloaded the uChp PDF and there is no Write Protect pin, just 3 chip select/address lines.
If those are all tied to ground then it's addess should be 0xA0/0xA1.
It is important to know which EEPROM it is, the Atmel ones ARE different, so you can't use the Atmel datasheet when using the uChp device.
If this is a homemade PCB check for shorts or grounds.
If an 'experimenters board', again, confirm all the wiring.
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 07, 2017 12:50 pm |
|
|
SubhamayS wrote: | Pin: 1,2,3,4 of EEPROM connected to GND,
PIN- 8 to VCC (+5V),
PIN- 7 (WP) TO GND,
PIN- 5 (SDA) to PIN_B0
PIN- 6 (SDA) to PIN_B1
still not working.. |
(of course you mean SCL to PIN_B1)
You may have:
1. A defective 24LC32A chip. Try another one. Where did you get it ?
If from eBay, it could be a counterfeit, non-working chip.
2. A defective PIC, or pins B0 and B1 are bad on that PIC.
3. Defective connections or resistors.
4. Defective compiler.
5. Poor power supply regulation.
temtronic wrote: |
I just downloaded the uChp PDF and there is no Write Protect pin |
Go to this page:
http://www.microchip.com/wwwproducts/en/24LC32A
Click on the link for Documentation. Go down there and get the link
for the 24LC32A data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/21713M.pdf
The first chip diagram on the lower left has WP on pin 7. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Jul 07, 2017 2:34 pm |
|
|
hmm seems the A is important.....I downloaded the nonA version,sigh...
I have to wonder though HOW counterfeit EEPROMs could be profitable..do 'they' just make 8 legged 'devices' and put numbers on them? IE NOTHING inside ?? |
|
|
SubhamayS
Joined: 07 Mar 2012 Posts: 34 Location: jalpaiguri, India
|
|
Posted: Fri Mar 23, 2018 9:37 am |
|
|
PCM programmer wrote: | You may have:
1. A defective 24LC32A chip. Try another one. Where did you get it ?
If from eBay, it could be a counterfeit, non-working chip.
2. A defective PIC, or pins B0 and B1 are bad on that PIC.
3. Defective connections or resistors.
4. Defective compiler.
5. Poor power supply regulation. |
Its original. I bought it from microchipdirect.
and the PIC is working fine (PIN B0 & B1).
Changed the EEPROM IC. The problem still persists.
I am using ccs bootloader in this program.
Oscillator connected is 20 MHz with PLL5. can this be the issue ?
Configs are shown below.
Code: | #include <18F2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
#include <usb_bootloader.h> |
I have changed the default #use i2c in 2432.c file to the following ?
Code: | #use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL, slow=100000, FORCE_HW) |
as per the document : http://ww1.microchip.com/downloads/en/AppNotes/00989A.pdf
it says that the SDA and SCL pins are open-drain terminals,
and therefore require pull-up resistors to VCC (typically
10 kΩ for 100 kHz, and 2 kΩ for 400 kHz and 1 MHz) I am using 10 k pull-up resistors so I have mentioned slow=100000 in #use i2c.
BUT STILL NOTHING SEEM TO WORK !
PLEASE HELP ! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 23, 2018 10:05 am |
|
|
Post a link to a schematic and also a photo of your board.
To show images on this forum, you have to upload them to a free image
hosting website (ex. Tinypic.com) and then post either a link or a hotlink
to your post in this thread. Then we can see your images. If you post
a hotlink, don't make the images too big. Maybe 1024x768 max.
If you don't like Tinypic.com, there are other websites.
Do a web search for: free forum image hosting |
|
|
SubhamayS
Joined: 07 Mar 2012 Posts: 34 Location: jalpaiguri, India
|
|
Posted: Sun Mar 25, 2018 12:05 am |
|
|
PCM programmer wrote: | Post a link to a schematic and also a photo of your board. |
Please find below, the image of schematic.
http://i66.tinypic.com/2801g0z.jpg
Is it a problem with of the MSSP clock ? because I am using CCS USB bootloader in my board, 20 Mhz crystal, generating 48 MHz clock with PLL5. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Sun Mar 25, 2018 9:23 am |
|
|
Some comments:
Don't confuse Vusb on the PIC with the USB 5v line. Vusb, is an internal voltage developed by the on chip regulator, and _must_ have a nice low impedance cap mounted close to the chip and nothing else.
If you are using a device powered by an external source (you are), with a USB connection, USB _requires_ (yes, it's part of the spec), the connection sense signal.
Your MCLR connection doesn't work....
As shown, neither the reset button or the capacitive boot circuit can ever take MCLR low.
You only show 1*0.1uF capacitor. There should be at least another on the EEPROM.
The size of the pull-ups is dependant on the I2C clock speed, and the capacitance on the bus. How long are the I2C connections?. What sort of wire?.
Add the fuse NOPBADEN. This is probably the problem. You don't have any ADC setup line, and with the PBADEN (which I think defaults 'on'), the whole of PortB is setup for analog. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 25, 2018 9:38 pm |
|
|
I don't think it's the lack of NOPBADEN. The startup code in main() sets
the PCFGx bits to all 1's in ADCON1, which makes PortB all digital i/o.
Quote: |
.................... void main(void)
0004: CLRF TBLPTRU
0006: BCF RCON.IPEN
0008: MOVLW 60
000A: MOVWF OSCCON
000C: MOVF OSCCON,W
000E: CLRF rs232_errors
0010: BCF BAUDCON.BRG16
0012: MOVLW 19
0014: MOVWF SPBRG
0016: MOVLW A6
0018: MOVWF TXSTA
001A: MOVLW 90
001C: MOVWF RCSTA
001E: MOVF ADCON1,W
0020: ANDLW C0
0022: IORLW 0F
0024: MOVWF ADCON1
0026: MOVLW 07
0028: MOVWF CMCON
|
I think it's got to be something like:
1. The SDA and SCL lines are swapped.
2. The 10K resistors are really 1 Meg.
3. Some connection that is shown is actually not there or is a cold-solder joint.
Or something like that. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Mon Mar 26, 2018 12:00 am |
|
|
Did you check with 5.015?.
I remember some versions about that time did not default to disabling the ADC. It would explain the behaviour.
I'll have to go and see if I have .015 to test. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 26, 2018 12:27 am |
|
|
vs. 5.015 does the same thing. It sets PortB to all digital.
Code: |
CCS PCH C Compiler, Version 5.015, xxxxx 25-Mar-18 23:25
0004: CLRF TBLPTRU
0006: BCF RCON.IPEN
0008: MOVLW 60
000A: MOVWF OSCCON
000C: MOVF OSCCON,W
000E: CLRF rs232_errors
0010: BCF BAUDCON.BRG16
0012: MOVLW 19
0014: MOVWF SPBRG
0016: MOVLW A6
0018: MOVWF TXSTA
001A: MOVLW 90
001C: MOVWF RCSTA
001E: MOVF ADCON1,W
0020: ANDLW C0
0022: IORLW 0F
0024: MOVWF ADCON1 // PCFGx bits = 1111
0026: MOVLW 07
0028: MOVWF CMCON |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|