I2C how to get started (AP8)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I2C how to get started (AP8)

1,390 Views
peblink
Contributor I
Hi everyone!
Im new to uC's and more to I2C and after reading datasheets and forum messages I stil cant get it runnig. Im using CW5 and I want to use the I2C module . In main I´ve initialized the MMI2C as follows (this came from a reply to another topic)

MMCR1 = 0x80;
MMCR2 = 0x30; /* Enable I2C master mode, interrupts enabled */
MMFDR = 0x02; /* Freq = 50kHz with 4MHz Xtal*/
MMSR = 0x00;

and then I call I2C_Tx_start() and I2C_Tx_stop() in a while loop. I dont really agree with the code and also tried other options but they wont work either. I want to transmit data to a 24FC512 eeprom using this code (based on MC68HC908AP64 datasheet, page 242)

void I2C_Tx_start (void){
MMSR_MMTXBE=0; /* start condition code
MMCR2_MMRW=0;
MMCR2_MMAST=1;

MMADR = 0xA0; /* Dev. address 00 */

MMSR_MMTXBE = 1;
MMSR_MMTXIF = 1; /* acknowledge */

MMDTR = 0XAA; /* dummy data to memory */
}
void I2C_Tx_stop(void){
MMSR_MMTXBE = 1; /* acknowledge */
MMSR_MMTXIF = 1;

MMCR2_MMNAKIF=1; /* stop*/
MMCR2_MMAST=0;
MMSR_MMTXBE = 1;
}

SCL is low all the time and SDA always high. I believe the problem is in the initialization. The device address is 00 (using A2,A1,A0 = 0) Could someone please give feedback on this problem? Thanks in advance
Labels (1)
0 Kudos
2 Replies

382 Views
peblink
Contributor I
Hey thanks for your reply. I had the pull up resistor only on SDA but it stays high all the time. I placed another in SCL, now it works but SDA wont change, same result with the code generated by processor expert. I also replaced both IC's (uController and I2C) but no difference. Any ideas?

Thanks
0 Kudos

382 Views
chapster
Contributor I
Processor Expert produces code to use I2C whichI have used successfully.  If this bean is not included in your license get hold of a temporary license and you will be able to view the code. 
 
If this is not the problem have you used pull up resistors on SCL and SDA?
0 Kudos