I2C reading

cancel
Showing results for 
Search instead for 
Did you mean: 

I2C reading

7,285 Views
Hagen
Contributor I
Hello everyone!!
 
I'm working with HCS12NE64 micrcontroller on a SE2PROM application. the writing routine works with out problem, but the reading. I have modified the Clock speed several times without success; once I catch the incoming data in IBDR, I store it in an array, but the data isn't that really is. I work over HCs12 CodeWarrior and I am programming in C. I can't find a bit that solves the Rx truoble.
 
Thanks for your cooperation.
Giovanni Garcia
Labels (1)
0 Kudos
7 Replies

426 Views
samiran_cj
Contributor I
Thank you for your solution Hagen.
I followed AN2318/D and now have working the I2C24WC32 in Debug mode with breakpoint set after writing each 32 byte page.

With Normal execution at speed it will not run correct. Something different is happening. How to trace execution at full speed.
0 Kudos

426 Views
samiran_cj
Contributor I

I used the information in CAT24WC32-64 datasheet to send addresses and data. The section on Acknowledge Polling indicates the EEProm takes time to do the writes.Never got any Acks though. I had to use a delay timer instead of a breakpoint at the end of each packet write. I dont really understand how but anyway it works.

 

 

0 Kudos

426 Views
Nabla69
Contributor V
Hi Hagen,
For you and others, may be the attached Excel spreadsheet will be useful. It allows you to calculate the I²C parameters on S12.
Please keep us posted if it helped you...
Alvin.
0 Kudos

426 Views
Hagen
Contributor I
It's me again, Hagen.
if somebody can help me, my MSN contact is
 
Thanks!
0 Kudos

426 Views
Hagen
Contributor I
Before I received the reply for my message, I changed the SCLK frequency and works. The troubble is:
I need to read from the slave device, a serial E2PROM memory (24LC256); it's seems the microcontroller can't hold on the information from memory because the micro read the IBDR but inmediatly change to the next data and can't store on memory. I tried testing with many bit flags: TCF, IBB, and IBIF, without success, sometimes it can recognize those bits and go to the next instruction, sometimes doesn't. In additon, I work my I2C read routine in polling mode but Interruption mode. Something peculiar, sometimes the SRW bit is set and I don't have the micro as Slave, just Master. Why happens this?
 
here go a part of the code in C:
 
/******************************************************************/
/* c. Re-Enviar Señal de START */
       IIC_Start(leer);
/* d. Tomar los datos que lee en BDR y pasarlos a Buffer de Rx Data_I2C */
       for(i=0;i<=*Tam_buf_I2C;i++){
       while(!b_TestBit(IBSR_IBIF,IBSR));        /* mientra bus está ocupado */  
  
  dummy_I2C = IBDR;
  Data_I2C[i]= dummy_I2C;          //dummy_I2C;
       b_SetBit(IBSR_IBIF,IBSR);      
       }
       b_ClearBit(3,IBCR);       // envia un ACK y termina
       IIC_Stop();
/* Deshabilitar Modulo I2C para evitar Flag de BusyBus inexistentes*/
       IBCR &= 0x7F;
/******************************************************************/
 
IICStart(leer) is a function that re-send the START signal and then the Slave address with last bit Set (R=1).
After that I wait for incoming data, reading the IBDR; in debugging mode works, that is, with BreakPoints in Code Warrior's Realtime Debugger. With out break points the micro only watches 0xFF, 0x00 even 0x01. I thougth the problem is Clock Speed, so I changed to 75KHz without success.
 
1. Is needed the I2C module works only in Interrupt mode?
2. in polling mode, exists a flag bit that lets me work in this mode?
 
Thanks for your Help!
 
Giovanni Garcia
0 Kudos

426 Views
imajeff
Contributor III

1. Is needed the I2C module works only in Interrupt mode?
2. in polling mode, exists a flag bit that lets me work in this mode?



Since there is not extra byte buffering in the IIC hardware, then the ISR is necessary if you cannot poll fast enough before the next byte arrives. So a slower bitrate could possibly make the polled mode possible.
0 Kudos

426 Views
Hagen
Contributor I
Yes, I verified and works my hardware using the interrupt mode as is explain in the Freescale's "AN2318 - Using the I2C Bus" document. Now I can read and write in a SE2PROM memory. However, you must be carefull with overwriting pages, because the memory over rolls the page and write where was wrote.
 
Thanks and enjoy the Freescale Microcontrollers, they're the best!
Hagen
0 Kudos