I'm configuring the i2c communication with LMP91002 AFE device. Now I've to write the i2c_read and i2c_write method.
Can anyone please share the theory for i2c_read and i2c_write method in VS1010?
Example of MSP430 code attached below.
I2C_WRITE:
Code: Select all
/*****************************************************************************
* Module : HALI2C_Write
* Description : sends out array of data over i2c bus
* Return : uint8_t ACK/NACK
*****************************************************************************/
uint8_t HALI2C_Write(uint8_t byte_count, uint8_t *data, uint8_t stop_bit){
uint8_t i = 0;
// handle NACK
NACK_FLAG = 0;
// Limit the Max num of transaction to 8 bytes per transfer
if(byte_count > 8)
{
byte_count = 8;
}
// controls the stop bit at the end of transaction
STOP_BIT_Flag = stop_bit;
// Init I2C master with counter and stop bits
HALI2C_masterInit(0, EUSCI_B_I2C_NO_AUTO_STOP);
//Set Master in transmit mode
EUSCI_B_I2C_setMode(EUSCI_B0_BASE,
EUSCI_B_I2C_TRANSMIT_MODE
);
//Enable I2C Module to start operations
EUSCI_B_I2C_enable(EUSCI_B0_BASE);
EUSCI_B_I2C_clearInterruptFlag(EUSCI_B0_BASE,
EUSCI_B_I2C_TRANSMIT_INTERRUPT0 +
EUSCI_B_I2C_NAK_INTERRUPT
);
//Enable master Receive interrupt
EUSCI_B_I2C_enableInterrupt(EUSCI_B0_BASE,
EUSCI_B_I2C_TRANSMIT_INTERRUPT0 +
EUSCI_B_I2C_NAK_INTERRUPT
);
//Update global array
TXByteCtr = byte_count;
for(i = 0; i< byte_count; i++)
{
TXData[i] = data[i];
}
while (EUSCI_B_I2C_SENDING_STOP == EUSCI_B_I2C_masterIsSTOPSent
(EUSCI_B0_BASE)) ; // Make sure bus is free
// start the transfer
TXByteCtr--; // When you reach ISR you would have sent already a byte
EUSCI_B_I2C_masterMultiByteSendStart(EUSCI_B0_BASE, TXData[0]);
__bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts
//Enable I2C Module to start operations
EUSCI_B_I2C_disable(EUSCI_B0_BASE);
return NACK_FLAG;
}