CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC18F2550 eeprom 24LC32A interfacing problem
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon Mar 26, 2018 12:56 am     Reply with quote

OK.
It's not that then.
It just seemed to be a likely cause of the behaviour.
I notice it's also setting up the comparator, so that's another thing that can be ruled out.

Agreed wholeheartedly on likely hardware issues.
That's one reason I mention the Vusb. The chips _require_ the capacitor on Vusb, even if USB is not being used, if the regulator is enabled. They can give some very odd issues if this is not present, since then the USB regulator will oscillate....

One other thought comes to mind. He talks about using a bootloader, but then posts his fuses. If the bootloader fuses do not match these, then the whole chip may not actually be configured as is being posted (since these override any fuses set in the main code). So, can you post the fuses used in the bootloader please?.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 26, 2018 6:54 am     Reply with quote

yeesh, I missed the part about using a bootloader...it'd be nice to see the whole,complete program as there could be 'something' else clobbering the EEPROM access !
It's extremely hard to debug without known all the facts so please, post your entire program.
SubhamayS



Joined: 07 Mar 2012
Posts: 34
Location: jalpaiguri, India

View user's profile Send private message

PostPosted: Wed Mar 28, 2018 9:54 am     Reply with quote

Ttelmah wrote:
.....The chips _require_ the capacitor on Vusb, even if USB is not being used....... So, can you post the fuses used in the bootloader please?.


I have used a 4.7 uF cap connected to the Vusb pin. Sorry I forgot to include that in the schematic.. Embarassed & I am posting the complete code below...

temtronic wrote:
yeesh, I missed the part about using a bootloader...it'd be nice to see the whole,complete program as there could be 'something' else clobbering the EEPROM access !
It's extremely hard to debug without known all the facts so please, post your entire program.


2432.c

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);
}


Main Program:

Code:
#include <18F2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
#include <usb_bootloader.h>
#include <lcd.c>

#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);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Mar 29, 2018 3:15 am     Reply with quote

What are the fuses in your bootloader?. I've asked this before.
It is better to have the main code using #fuses none, and just put the bootloader fuses as a 'remark' the line after, so you then 'know' what fuses the processor actually has. Code loaded with a bootloader can't change the fuses (if it does the bootloader will stop working...), and it is the bootloader fuses your code will be using. So show these please.

A 4.7uF electrolytic is not actually a good capacitor for the Vusb pin, unless it is a very good HF type like an OSCON capacitor. A 0.47uF polyester is the recommended type, or a 1uF electrolytic, with a 0.1uF ceramic in parallel. Bigger is not better here, it is the high frequency performance that matters. Must be 220nF min (though later application notes from MicroChip increased this to 470nF).

I'd honestly prefer to see you setting the LCD pins up yourself. However it should be using PortD on your chip by default. Presumably this is working OK?.
So what is it showing?.

Also I repeat my question about the wiring to the EEPROM?. You have to understand that the pull-up resistors have to pull the signal up in a minimum time (part of the I2C spec). Whether they can, depends on the capacitance of the I2C bus, so depends on the connections used....
SubhamayS



Joined: 07 Mar 2012
Posts: 34
Location: jalpaiguri, India

View user's profile Send private message

PostPosted: Thu Mar 29, 2018 12:41 pm     Reply with quote

Ttelmah wrote:
What are the fuses in your bootloader?

The fuses used in the bootloader is given below. as given in ex_usb_common.h
Code:
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN

Ttelmah wrote:
A 4.7uF electrolytic is not actually a good capacitor for the Vusb pin, unless it is a very good HF type like an OSCON capacitor. A 0.47uF polyester is the recommended type...

Thanks for this information,, actually my board was working ok with 4.7uf cap at the Vusb. but I will change it to 0.47uf now.

The LCD is working fine. I am getting a display 'EEPROM DEMO', but nothing else appears after this.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Mar 29, 2018 2:24 pm     Reply with quote

I would compile and run PCM Ps 'I2C scanner' program from the code library. It will confirm what address the EEPROM is located at, assuming you've got the correct pullup resistors, of course.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Mar 29, 2018 2:34 pm     Reply with quote

Try reducing the speed from 48MHz to say 8MHz. I seem to recall a possible timing issue related to I2C devices vs. compler version, maybe 3-4 months ago. You should be able to reduce PIC clock without affecting the USB clock. Others may know for sure.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Mar 30, 2018 12:47 am     Reply with quote

Problem is he'll have to reload the bootloader if he does this. However the easiest setting is:
Code:

#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use_delay(clock=20MHz)


Which clocks the CPU off the crystal, instead of off the USB PLL.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Mar 30, 2018 5:49 am     Reply with quote

OK.. I tried your EEPROM section of code on an 18F46K22 and it works 100% even at 64MHz. I made minor changes to show sent and received data from EEPROM, looping from 32 to 255.

Code:

//================================
   init_ext_eeprom();            // to initialize EEPROM


   for(data=32;data<255;data++){      //loop printable character
   output_high(PIN_B2);
   write_ext_eeprom(0, data);
   lcd_gotoxy(1,1);                  
   printf(lcd_putc,"sent %d",data);   //show what was sent to loc 0
   delay_ms(10);
   output_high(PIN_B3);
   write_ext_eeprom(2, data+1);         
   lcd_gotoxy(1,3);
   printf(lcd_putc,"sent %d",data+1);   //show what was sent loc 2

   delay_ms(10);
   output_high(PIN_B4);
   lcd_gotoxy(11,1);
   printf(lcd_putc,"rcvd %d", read_ext_eeprom(0)); //dsp eeprom 0
   delay_ms(50);
   lcd_gotoxy(11,3);
   printf(lcd_putc,"rcvd %d", read_ext_eeprom(2)); //dsp eeprom 2
   delay_ms(50);
 
   delay_ms(1000);                  //wait 1 sec to see data
} //end of for loop                  //forever loop( 32 to 255 )



Since your program 'stops or stalls', I'm thinking the EEPROM is not connected properly.
SubhamayS



Joined: 07 Mar 2012
Posts: 34
Location: jalpaiguri, India

View user's profile Send private message

PostPosted: Sun Apr 01, 2018 9:19 am     Reply with quote

temtronic wrote:
OK.. I tried your EEPROM section of code on an 18F46K22 and it works 100% even at 64MHz..... Since your program 'stops or stalls', I'm thinking the EEPROM is not connected properly.


What value of pullup resistors you have used ?
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Apr 01, 2018 11:31 am     Reply with quote

4K7 as I'm using a VDD of 5V and close to the PIC.

Jay
SubhamayS



Joined: 07 Mar 2012
Posts: 34
Location: jalpaiguri, India

View user's profile Send private message

PostPosted: Mon Feb 17, 2020 10:25 am     Reply with quote

Ttelmah wrote:

A 4.7uF electrolytic is not actually a good capacitor for the Vusb pin, unless it is a very good HF type like an OSCON capacitor. A 0.47uF polyester is the recommended type, or a 1uF electrolytic, with a 0.1uF ceramic in parallel. Bigger is not better here, it is the high frequency performance that matters. Must be 220nF min (though later application notes from MicroChip increased this to 470nF).


Just wanted to verify my design... as per your suggestion I am changing the capacitor at Vusb pin to 470 nF. But which type should I use.. !! electrolytic or ceramic ???? please suggest.... Thanks in advance. Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon Feb 17, 2020 10:40 am     Reply with quote

Multilayer ceramic.
You want a really low ESR & good HF response.
The alternative quite a few people use is a 1uF electrolytic, in parallel with
a 0.1uF ceramic. This boosts the HF response that electrolytics tend to
lack.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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