// Func: Issue IIC Restart Condition
// Args: -
// Retn: -
//
void restartIIC(void) {
IBCR |= BM_RSTA; // issue RESTART condition
}
//-----------------------------------------------------------------------------
// Func: Issue IIC Stop Condition
// Args: -
// Retn: -
//
void stopIIC(void) {
IBCR = BM_IBEN; // back to slave mode (issue STOP cond.)
}
//-----------------------------------------------------------------------------
// Func: Transmit byte via IIC
// Args: bval: data byte to transmit
// Retn: if stat==0 then IIC_ACK else IIC_NOACK
//
UINT8 sendIIC(UINT8 bval) {
UINT8 stat;
// IBCR = BM_IBEN | BM_MSSL | BM_TXRX; // still transmit mode, still master
IBDR = bval; // transmit byte
while((IBSR & BM_IBIF) == 0) // wait for transfer done
; // CAUTION! no loop time limit implemented
stat = IBSR & BM_RXAK; // mask ACK status (0==ACK)
IBSR = BM_IBIF; // clear IB Intr Flag
return stat;
}
//-----------------------------------------------------------------------------
// Func: Receive byte from IIC
// Args: ack = IIC_ACK / IIC_NOACK
// Retn: byte received
//
UINT8 receiveIIC(UINT8 ack) {
UINT8 bval;
IBCR = BM_IBEN | BM_MSSL; // receive mode (still master)
if(ack != IIC_ACK) IBCR |= BM_TXAK; // set TXAK to respond with NOACK
bval = IBDR; // dummy read initiates transfer
while((IBSR & BM_IBIF) == 0) // wait for transfer done
; // CAUTION! no loop time limit implemented
IBSR = BM_IBIF; // clear IB Intr Flag
IBCR = BM_IBEN | BM_MSSL | BM_TXRX; // back to transmit mode, still master
bval = IBDR; // get received byte
return bval;
}
//=============================================================================
The IIC-Bus signals are acessible at X4/65+66.
User Manual
33