Antonio Quevedo

I2C Slave device on 9S08EL16

Discussion created by Antonio Quevedo on Sep 8, 2011
Latest reply on Sep 13, 2011 by Antonio Quevedo



I am trying to use a 9S08EL16 as an I2C slave device. This device will control 6 PWM channels, and pulse widths are determined by I2C commands. However, my device is not recognizing the I2C address sent by the master.


I am using a TWR-MECH board with its original firmware as a master to send I2C commands, so It should probably be working OK. The onboard accelerometer works on I2C interface, and it is being correctly read by the main board.


I am running my EL16 device through CodeWarrior Debugger and BDM. I had set up a breakpoint at the point of the program where I2C address has been matched. When I command the TWR-MECH to send an I2C command to my device, it stays in the address match loop, without leaving it and breaking execution. Thus, address is not being recognized.


Here is the part of my code where I initialize the I2C and then I try to get a command issued to my device:


IICC2 = 0x00; //No general calls, 7-bit address

IICA = 0xC0; // defines IIC address 60 hexa for the module. 0xC0 = 0x60 << 1

IICC1 = 0x80; // Enables IIC in slave mode, receive mode, with ACK signal, without repeated START  


/* Main loop */

for(; ; ) {

    while(!(IICS & 0x40)); // waits until address match (bit 6)

    rw = IICS & 0x04; // isolates R/W bit. BREAKPOINT IS HERE!!!!!!

    while(!(IICS & 0x80)); // waits until data received (bit 7)

    cmd = IICD; // reading IICD clears IICS bit 7. Here is the command

    if(rw) {

        parser_read(); // slave read routine

     } else {

        while(IICS & 0x80); // waits until data received

        iicdata = IICD; // Now gets data byte, clearing IICS bit 7

        parser_write(); // command parser for slave write routine


    IICC1 = 0x80; // clears IICS bit 6 by writing to register IICC

    // end of main loop



There is a periodic interrupt of 25ms period. Could it be the reason of address matching failure?


Thanks in advance