Other Parts Discussed in Thread: TMDS570LS31HDK, HALCOGEN, LP8866EVM,
I'm using TMDS570LS31HDK evaluation board and CCS v12.5.0, Halcogen v04.07.01.
Also I'm using LP8866EVM for our project so, I want to communicate LP8866EVM on I2C with TMS570LS3137.
I setted halcogen configuration as below.
and my code is below.
#include "sys_common.h"
/* USER CODE BEGIN (1) */
#include "gio.h"
#include "i2c.h"
#include "het.h"
#include "TMS_I2c.h"
hetSIGNAL_t het1;
uint8_t tx_data[3] = { 0x02, 0xFF, 0x00 };
uint8_t rx_data[2] = { 0 };
uint16_t delay = 0;
void TMS_I2c_recv(uint8_t slaveAddr, uint8_t memAddr,uint8_t memAddrLen, uint8_t *recvBuf, uint8_t len)
{
i2cSetSlaveAdd(i2cREG1, slaveAddr);
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
i2cSetCount(i2cREG1, memAddrLen);
i2cSetMode(i2cREG1, I2C_MASTER);
i2cSetStop(i2cREG1);
i2cSetStart(i2cREG1);
i2cSend(i2cREG1, memAddrLen,(uint8_t *) &memAddr);
while(i2cIsBusBusy(i2cREG1) == true);
while(i2cIsStopDetected(i2cREG1) == 0);
i2cSetSlaveAdd(i2cREG1, slaveAddr);
i2cSetDirection(i2cREG1, I2C_RECEIVER);
i2cSetCount(i2cREG1, len);
i2cSetMode(i2cREG1, I2C_MASTER);
i2cSetStop(i2cREG1);
i2cSetStart(i2cREG1);
i2cReceive(i2cREG1, len, recvBuf);
while(i2cIsBusBusy(i2cREG1) == true);
while(i2cIsStopDetected(i2cREG1) == 0);
i2cClearSCD(i2cREG1);
// for(delay=0;delay<3;delay++);
}
int main(void)
{
gioInit();
gioSetBit(gioPORTA, 0, 1); // Enable for LP8866EVM
i2cInit();
// pwm init for LP8866EVM
hetInit();
pwmStart(hetRAM1, pwm0);
het1.duty = 2;
het1.period = 100;
pwmSetSignal(hetRAM1, pwm0, het1);
while (1)
{
TMS_I2c_recv(0x2b, 0x1A, 1, rx_data, 2); // our I2C address is 0x2B.
return 0;
}
I2C config as below;
void i2cInit(void)
{
/* USER CODE BEGIN (3) */
/* USER CODE END */
/** @b initialize @b I2C */
/** - i2c Enter reset */
i2cREG1->MDR = (uint32)((uint32)0U << 5U);
/** - set i2c mode */
i2cREG1->MDR = (uint32)((uint32)0U << 15U) /* nack mode */
| (uint32)((uint32)0U << 14U) /* free running */
| (uint32)(0U) /* start condition - master only */
| (uint32)((uint32)1U <<11U) /* stop condition */
| (uint32)((uint32)0U <<10U) /* Master/Slave mode */
| (uint32)((uint32)I2C_TRANSMITTER) /* Transmitter/receiver */
| (uint32)((uint32)I2C_7BIT_AMODE) /* xpanded address */
| (uint32)((uint32)0U << 7U) /* repeat mode */
| (uint32)((uint32)0U << 6U) /* digital loop back */
| (uint32)((uint32)0U << 4U) /* start byte - master only */
| (uint32)((uint32)0U << 3U) /* free data format */
| (uint32)(I2C_8_BIT); /* bit count */
/** - set i2c Backward Compatibility mode */
i2cREG1->EMDR = 0U;
/** - Disable DMA */
i2cREG1->DMACR = 0x00U;
/** - set i2c data count */
i2cREG1->CNT = 8U;
/** - disable all interrupts */
i2cREG1->IMR = 0x00U;
/** - set prescale */
i2cREG1->PSC = 0U;
/** - set clock rate */
i2cREG1->CKH = 33U;
i2cREG1->CKL = 33U;
/** - set i2c pins functional mode */
i2cREG1->PFNC = (0U);
/** - set i2c pins default output value */
i2cREG1->DOUT = (uint32)((uint32)0U << 1U) /* sda pin */
| (uint32)(0U); /* scl pin */
/** - set i2c pins output direction */
i2cREG1->DIR = (uint32)((uint32)0U << 1U) /* sda pin */
| (uint32)(0U); /* scl pin */
/** - set i2c pins open drain enable */
i2cREG1->PDR = (uint32)((uint32)0U << 1U) /* sda pin */
| (uint32)(0U); /* scl pin */
/** - set i2c pins pullup/pulldown enable */
i2cREG1->PDIS = (uint32)((uint32)1U << 1U) /* sda pin */
| (uint32)(1U); /* scl pin */
/** - set i2c pins pullup/pulldown select */
i2cREG1->PSEL = (uint32)((uint32)1U << 1U) /* sda pin */
| (uint32)(1U); /* scl pin */
/** - set interrupt enable */
i2cREG1->IMR = (uint32)((uint32)0U << 6U) /* Address as slave interrupt */
| (uint32)((uint32)0U << 5U) /* Stop Condition detect interrupt */
| (uint32)((uint32)0U << 4U) /* Transmit data ready interrupt */
| (uint32)((uint32)0U << 3U) /* Receive data ready interrupt */
| (uint32)((uint32)0U << 2U) /* Register Access ready interrupt */
| (uint32)((uint32)0U << 1U) /* No Acknowledgement interrupt */
| (uint32)((uint32)0U); /* Arbitration Lost interrupt */
/** - i2c Out of reset */
i2cREG1->MDR |= (uint32)I2C_RESET_OUT;
/** - initialize global transfer variables */
g_i2cTransfer_t.mode = (uint32)0U << 4U;
g_i2cTransfer_t.length = 0U;
/* USER CODE BEGIN (4) */
/* USER CODE END */
}
so, I have communicated to I2C with our slave. But, If you attention our my code, our receieve code is running in the infinite loop, so, I need to receieve continously. but as you can see below in logic analyzer, I have take after few times and I2C is being bus busy.
in the last picture of the logic analyzer, in the last data is coming NACK. whenas, data need to continous. why I do not take continously in the infinite loop?