Other Parts Discussed in Thread: LMK05318,
I am making some tests in order to write and read, using TM4C1294 microcontroller and I2C protocol, LMK05318 registers.
LMK05318 has registers made-up of two bytes (however, only the nine less significant bits are used ). Instead, the length of each register's content is 8 bits.
I2C is working in fast mode
The issue is that only one of the register's address bytes is sent through I2C.
If I write the register with the address 0x013F (the register's content is 0x18), the logic analyzer shows that the second byte 0x3F is not sent. Therefore, only the following bytes are sent through I2C: 0xF0 (device address) 0x01,0x18.
Instead, when the register is written with "TicsPro" software, the logic analyzer shows that all the bytes are transmitted: 0xF0, 0x01,0x3F, 0x18 (0xF0 is always the device address)
I have also made a test by inserting the expression I2CMasterBurstLengthSet (I2C5_BASE,3) before the transfer of the three bytes begins. With this expression, the logic analyzer shows that the following bytes are transmitted 0xF0,0x3F,0x18.
What am I missing? Thanks in advance
#define LMK_SLAVE_ADDRESS 0x78
void LMK05318_write(void);
void LMK05318_read_registers(void);
void LMK05318_read_registers(void)
{
volatile uint8_t data_read=0;
I2CMasterSlaveAddrSet(I2C5_BASE, LMK_SLAVE_ADDRESS, false);
I2CMasterDataPut(I2C5_BASE, 0x01);
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_START);
//wait for MCU to finish transaction
while(I2CMasterBusy(I2C5_BASE));
I2CMasterDataPut(I2C5_BASE,0x3F); //low byte
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusy(I2C5_BASE));
while(I2CMasterBusy(I2C5_BASE));
//specify that we are going to read from slave device
I2CMasterSlaveAddrSet(I2C5_BASE, LMK_SLAVE_ADDRESS, true);
//send control byte and read from the register we //specified
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
//wait for MCU to finish transaction
while(I2CMasterBusy(I2C5_BASE));
//return 1st byte pulled from the specified register
data_read = I2CMasterDataGet(I2C5_BASE);
GPIO_PORTK_DATA_R|=0x10;
}
void LMK05318_write(void)
{
I2CMasterSlaveAddrSet(I2C5_BASE, (LMK_SLAVE_ADDRESS), false);
while (I2CMasterBusy(I2C5_BASE));
//I2CMasterBurstLengthSet (I2C5_BASE,3);
I2CMasterDataPut(I2C5_BASE,0x01); //high byte
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while (I2CMasterBusy(I2C5_BASE));
while (I2CMasterBusy(I2C5_BASE));
I2CMasterDataPut(I2C5_BASE, (0x3F)); //low byte
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy(I2C5_BASE));
while (I2CMasterBusy(I2C5_BASE));
I2CMasterDataPut(I2C5_BASE, 0x18);//low byte
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while (I2CMasterBusy(I2C5_BASE));
while (I2CMasterBusy(I2C5_BASE));
}
int main(void)
{
uint32_t ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
uint32_t sysCtlPeripheral = SYSCTL_PERIPH_I2C5;
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C5);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2); //LED
GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_4); //LED
GPIOPinConfigure(GPIO_PB4_I2C5SCL);
GPIOPinConfigure(GPIO_PB5_I2C5SDA);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_5);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_4);
I2CMasterInitExpClk(I2C5_BASE, ui32SysClock, true);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C5));
I2CMasterEnable(I2C5_BASE);
GPIO_PORTA_AHB_DATA_R =0x00;
GPIO_PORTC_AHB_DATA_R =0x00;
GPIO_PORTK_DATA_R =0x00;
GPIO_PORTJ_AHB_DATA_R =0x00;
GPIO_PORTQ_DATA_R =0x00;
LMK05318_write();
SysCtlDelay(10000);
LMK05318_read_registers();
while(1)
{
GPIO_PORTK_DATA_R|=LED_RED;
SysCtlDelay(10000);
GPIO_PORTA_AHB_DATA_R |=LED_BLU;
SysCtlDelay(10000);
}
}