EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

68HC12 Microcontroller as slave

Started by "Dhi...@buffalo.edu [68HC12]" July 28, 2015
Hi,

I am trying to use this 68HC12 microcontroller in slave mode for I2C
Communication. Is there any sample code which puts the controller in slave
mode and used to communicate with another master? Please help me since i am
working on this for a long time and i could not figure what is wrong. Is it
software code or hardware setup?? Please help me with the sample code.

Thanks,
Dhinesh.








This ISR (and initialization code) for the 68HCS12 and GCC C compiler receives data and displays by writing to PORTB and sends data from PTIH. This matches switches and LEDs on a Dragon-12 board.

    IBFD = 0x23; // 100KHz operation
//    IBFD = 0x35; // 20KHz operation
    IBAD = 0x20 << 1;    // Slave address is 0x20 
    IBCR |= 0xC0; // Set IBEN and IBIE
    UserIIC = (unsigned int) &iicisr;


    iicState = IIC_IDLE;
...
enum {IIC_IDLE, IIC_TRANSMITTING, IIC_RECEIVING} iicState;

void INTERRUPT iicisr(void) {

    IBSR &= 0x02; // Reset flag

    switch (iicState) {

        case IIC_IDLE:

            if ((IBSR&0x40)!=0) { // IAAS set -- we are addressed

                if ((IBSR&0x04) != 0) { // Slave transmit

                    IBCR |= 0x10; // set TX bit

                    putChar('T');

                    IBDR = PTIH; // Send switches

                    iicState = IIC_TRANSMITTING;

                } else { // Slave receive

                    IBDR; // fake read to start receive

                    iicState = IIC_RECEIVING;

                }

            } else { // Toss out anything here

                putChar('I');

                IBDR;

            }

            break;

        case IIC_TRANSMITTING:

            if ((IBSR&1) == 0) { // we were ACKed so continue

                putChar('T');

                IBDR = PTIH; // Send switches AGAIN!

            } else { // We were NAKed

                IBCR &= ~0x10; // Clear TX bit

                IBDR; // Dummy read to finish

                iicState = IIC_IDLE;

            }

            break;

        case IIC_RECEIVING:

            putChar('R');

            PORTB = IBDR; // We will receive one -- additional bytes ignored (Idle state toss code

            IBCR |= 0x80; // Fake write of IBCR to clear IAAS bit

            iicState = IIC_IDLE;

            

    }



}





-------- Original Message --------

Subject: [68HC12] 68HC12 Microcontroller as slave

From: "Dhinesh Raja Kannan d...@buffalo.edu [68HC12]"

<6...>

Date: Tue, July 28, 2015 10:35 am

To: 6...





Hi,

I am trying to use this 68HC12 microcontroller in slave mode for I2C Communication. Is there any sample code which puts the controller in slave mode and used to communicate with another master? Please help me since i am working on this for a long time and i could not figure what is wrong. Is it software code or hardware setup?? Please help me with the sample code.

Thanks,
Dhinesh. 














__._,_.___





Posted by: <t...@almy.us>







stime38117238





















__,_._,___

The 2024 Embedded Online Conference