Hi all,
I'm trying to get some data from an I2C slave, but the program gets stuck in I2CMasterBusy(I2C2_BASE), when using I2C2. I can't get any signal with the scope. I have pull-up resistors in SCL and SDA.
When I try to use I2C5, it works fine.
I can get some direction in this issue, please?
#include <stdbool.h> #include <stdint.h> #include "inc/hw_i2c.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/gpio.h" #include "driverlib/i2c.h" #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "utils/uartstdio.h" #define SLAVE_ADDRESS 0b10011010 #define REGISTER 0x00 //read specified register on slave device uint32_t I2CReceive(uint8_t slave_addr, uint8_t reg) { //specify that we are writing (a register address) to the //slave device I2CMasterSlaveAddrSet(I2C2_BASE, slave_addr, false); //specify register to be read I2CMasterDataPut(I2C2_BASE, reg); //send control byte and register address byte to slave device I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_START); SysCtlDelay(100); //wait for MCU to finish transaction while(!(I2CMasterBusy(I2C2_BASE))); SysCtlDelay(100); while(I2CMasterBusy(I2C2_BASE)); //specify that we are going to read from slave device I2CMasterSlaveAddrSet(I2C2_BASE, slave_addr, true); //send control byte and read from the register we //specified I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE); SysCtlDelay(100); //wait for MCU to finish transaction while(!(I2CMasterBusy(I2C2_BASE))); SysCtlDelay(100); while(I2CMasterBusy(I2C2_BASE)); //return data pulled from the specified register return I2CMasterDataGet(I2C2_BASE); } //***************************************************************************** // // Configure the I2C5 master. // //***************************************************************************** volatile uint32_t test = 0; void main(void) { uint32_t ui32SysClock; ui32SysClock = SysCtlClockFreqSet((SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // The I2C2 peripheral must be enabled before use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C2)) {} SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); GPIOPinConfigure(GPIO_PN4_I2C2SDA); GPIOPinConfigure(GPIO_PN5_I2C2SCL); GPIOPinTypeI2CSCL(GPIO_PORTN_BASE, GPIO_PIN_5); GPIOPinTypeI2C(GPIO_PORTN_BASE, GPIO_PIN_4); I2CMasterInitExpClk(I2C2_BASE, ui32SysClock, false); // Enable Power in External Conector SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE, GPIO_PIN_0); GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_0, ~0); for(;;) { test = I2CReceive(REGISTER, ID_ADDRESS); SysCtlDelay(60000000); //~500 ms } }