Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with code for writing and reading data from PIC18f452 to 24c08

Status
Not open for further replies.

Naumanpak

Member level 2
Joined
Nov 19, 2009
Messages
51
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Pakistan
Activity points
1,635
Experts,

I need to write and read data to slave(24c08).

I am using mikroc PIC I2C library. And the Library Example.

PROBLEM:

Doesnt work.

On debugging I notice that it never sends a byte after start. Perhaps clock not generated??

Kindly suggest me.

thanks

Code:
void main() {
  char x;
  char *text1 = "Testing";

  TRISB = 0;                // PORTB is output
  Lcd_Init(&PORTB);         // Initialize LCD connected to PORTB
  Lcd_Cmd(Lcd_CLEAR);       // Clear display
  Lcd_Cmd(Lcd_CURSOR_OFF);  // Turn cursor off

  I2C_Init(100000);
  I2C_Start();
          // Issue I2C start signal
  I2C_Wr(0xA2);          // Send byte via I2C 
  Lcd_Out(2,1, text1);  //not displayed
  I2C_Wr(2);             // Send byte (address of EEPROM location)
  I2C_Wr(0xF0);          // Send data (data to be written)
  I2C_Stop();

  Delay_ms(100);

  I2C_Start();           // Issue I2C start signal
  I2C_Wr(0xA2);          // Send byte via I2C  (device address + W)
  I2C_Wr(2);             // Send byte (data address)
  I2C_Repeated_Start();  // Issue I2C signal repeated start
  I2C_Wr(0xA3);          // Send byte (device address + R)
  x=I2C_Rd(0u);    // Read the data (NO acknowledge)
  I2C_Stop();
  Delay_ms(100);
  Lcd_chr(4, 1, x);
}
 

PIC to 24c08

are you sure, it generates a good START condition? maybe you have forgotten to set pull-ups for SDA or SCL...

maybe you can attach your schematics (by the way... which pic are you using?)
 

    Naumanpak

    Points: 2
    Helpful Answer Positive Rating
Re: PIC to 24c08

Hi, thanks for a reply.

I am using PIC18f452.

Kindly, check these cases out for start check.

I2C_Start();
I2C_Wr(0xA2); // Send byte via I2C
Lcd_Out(2,1, text1); //not displayed

In other case,

I2C_Start();
Lcd_Out(2,1, text1); // displayed
I2C_Wr(0xA2); // Send byte via I2C


Also attached are the schematics, same for 18f452.

Please suggest, thanks again.

**broken link removed**
 

PIC to 24c08

I suggest using an scope, and tell us how is your PIC configurated (it should be as external clock, but the pic16f877 doesn't have that option so...? again, at which freq it's working)
but if it output over an LCD, I think the PIC is working well.

if you don't have an scope,
set some delays (about 3 secconds or more) before and after the I2C Start (for i2c as a sincronous, it doesn't care if you have delays...), so before the start, both lines SDA and SCL MUST BE logic 1 (5 volts) and AFTER Start SDA and SCL MUST BE both logic 0 (0 volts)
if its okay, just test it without the 24c08, it must give all clock pulses and recieve no acknowledge, so it will output, it wll continue, but have no answer, in that case, your 24c08 is fried...

checking the datsheet, this micro, implements the Clock Arbitration, wich suspends any communication until the slave device leaves SCL as High, so if your 24c08 is dead, maybe it leaves SCL low, and block the micro from continuing...

Also, how do you configure MikroC for I2c Master or i2c Slave? (i don't have the help file right now) maybe you set a slave instead a Master.... but i think this is an arbitration or collition issue...

check this and comment your results...
 

    Naumanpak

    Points: 2
    Helpful Answer Positive Rating
Re: PIC to 24c08

Hey thanks!

Its solved now! 10 points for you.

I have another question,

I have my database in MMC card but data rate is too low(~5kb/sec). What I want to do is load required data into serial RAM and do required operations.


Individually, I can read and write on both MMC card(SPI interface) and serial RAM(I2C).

But how do I access both as interfacing either requires RC3 and RC4 of 18F452.
Kindly post here


thanks again.
 

PIC to 24c08

mmmm, you can't access both SPI and I2C from the same pins at the same time! you can search for a PIC controller with two MSSP (one will be for the memory, and the other for the SD) (18f46j50)

other thing is to implement software I2C, but it's not as fast, but at least, you can reach the 100kHz. this could be your best option right now...

and lastly, you can try searching for a SPI memory somthing like the 23k256 or something SPI so you can sare MOSI and MISO (SDI and SDO) but connect a different CS for both SD an RAM...
 

    Naumanpak

    Points: 2
    Helpful Answer Positive Rating
Re: PIC to 24c08

Hey thanks, I will get back to this topic in a day.
 

PIC to 24c08

most of the mcu problems are casued by incorrect mcu initiation. the pins are multi-use and upon power up, they may not be in the right mode for your application (gpio).

so the first thing you should do with any mcu is to initialize the ports / pins so that they are in gpio mode, or whatever mode your application assumes it to be.
 

    Naumanpak

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top