Hi timmy10ar
Below I have sent you some pseudo code taken from a project which is reading things like temperature sensors and RTCs over the I2C bus. It is a M9S12NE64 but it looks as though the I2C controller is compatible with the one in your chip.
It is interrupt driven but the flow should be much the same as yours using polling. It is basically C-code but should be easily interpretable in assembler.
Perhaps you see something which is different?
Regards
Mark Butcher
www.mjbc.ch / www.uTasker.com
Configuration
{
IBFD = 0x89; // set IIC bus frequency
IBCR = (IBEN); // enable IIC bus
IBCR = (IBEN | MS_SL); // enable IIC bus in master mode
}
// Start command write
{
IBCR |= (MS_SL | TX_RX | IBIE); // generate start condition / enable IIC interrupt
IBDR = (ucAddress); // send the slave address
}
// on each tx interrupt (during tx phase)
IBSR |= IBIF; // clear the interrupt flag (by writing a '1')
if first interrupt
IBDR = cmd; // send command byte
else if second interrupt
IBCR |= RSTA; // restart since we are hanging a second telegram on to previous one
IBDR = (ucAddress | 0x01); // send the slave address
}
// On each interrupt (during read phase)
{
IBSR |= IBIF; // clear the interrupt flag (by writing a '1')
if first interrupt
IBCR &= ~TXAK; // ensure we acknowledge multibyte reads
IBCR &= ~TX_RX; // go to master receive mode
ucRx = IBDR; // dummy read
return
else if last but one byte
IBCR |= TXAK; // we don't acknowledge last byte
else if very last byte
IBCR &= ~MS_SL; // send end condition
IBCR &= ~(IBIE); // disable interrupts
*IIC_rx_control->IIC_queue.put++ = IBDR; // put received byte into input buffer
}