Part Number: TMS320F28377S
Tool/software: Code Composer Studio
Hi,
I am trying to interface it with VCNL4010(IR Sensor) over I2C and I have a problem. I have found a example code in device support and with reference to it, I have modified the code. But it's not working. On the osciloscope I have all the time high condition and I don't see any communication.
#include "F28x_Project.h"
void i2c_a_init (void);
void i2c_a_write_data(Uint16,Uint16);
Uint16 i2c_a_read_data (Uint16 register_address);
int main(void){
InitSysCtrl();
InitGpio();
i2c_a_init();
while(1){
i2c_a_write_data(0x81,0x07);
i2c_a_read_data (0x80);
}
}
void i2c_a_init (void)
{
I2caRegs.I2CSAR.all = 0x0026; // 7-bit Slave address - DS1672
EALLOW;
GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0;
GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0;
// Set qualification for the selected I2C pins
GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 3;
GpioCtrlRegs.GPBQSEL1.bit.GPIO33 = 3;
// Configure which of the possible GPIO pins will be I2C_A pins
// using GPIO regs
//
GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 1;
GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 1;
EDIS;
// Initialize I2C in master transmitter mode
I2caRegs.I2CPSC.all = 19; // I2C clock should be between 7Mhz-12Mhz
I2caRegs.I2CCLKL = 45; // Prescalers set for 100kHz bit rate
I2caRegs.I2CCLKH = 45; // At a 10Mhz I2C clock
I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO
I2caRegs.I2CFFRX.all = 0x2040; // Enable RXFIFO, clear RXFFINT
return;
}
void i2c_a_write_data (Uint16 register_address, Uint16 register_value)
{
//START condition, STOP condition, Master, Transmitter, I2C enabled
I2caRegs.I2CMDR.all = 0x2E20;
I2caRegs.I2CCNT = 0x02; // bytes to send - 2 here
I2caRegs.I2CDXR.all = register_address; // register location
I2caRegs.I2CDXR.all = register_value; // register location
}
Uint16 i2c_a_read_data (Uint16 register_address)
{
//START condition, STOP condition, Master, Transmitter, I2C enabled
I2caRegs.I2CMDR.all = 0x2E20;
I2caRegs.I2CCNT = 0x01; // bytes to send - always 1
I2caRegs.I2CDXR.all = register_address; // register location
// Start condition, Stop condition, Master, I2C enabled
I2caRegs.I2CMDR.all = 0x2C20;
I2caRegs.I2CCNT = 0x01; // bytes to receive - always 1
return I2caRegs.I2CDRR.all; // read and return data
}
Thank you for help
Best regards
Szymon

