Part Number: TMS320F280049
Other Parts Discussed in Thread: C2000WARE
Hi Team,
I am working on board which uses F280049 as micro and two ADC112C04s to measure thermocouple temperature. For communication I am using I2C protocol. As a first step I wrote a simple code for configuring the registers in ADC with address 0x40 ( A1 and A2 both connected to GND). I am attaching the code and respective scope shots below.
My question is there is any order should I keep to write the START and STOP signals in the code ?
Or If there is any other problem with my code please help me out.
My system clock frequency is 100 MHz.
IPSC register value = 9 so Fmod = 100/10 = 10MHz
I2C master clock = 10/200 = 50 kHz ( ICCL and ICCH = 95, d = 5)
#include"F28x_Project.h"
void main(void)
{
// Intiate system controls, GPIO pins, interrupt
uint16_t r1 = 0x0012;
InitSysCtrl();
InitGpio();
EALLOW;
GpioCtrlRegs.GPAGMUX2.bit.GPIO26 = 2; // I2CA_SDA
GpioCtrlRegs.GPAMUX2.bit.GPIO26 = 3;
GpioCtrlRegs.GPAQSEL2.bit.GPIO26 = 3; // Input qualification : Asynchronous
GpioCtrlRegs.GPAPUD.bit.GPIO26 = 0; // Pull up enable
GpioCtrlRegs.GPAGMUX2.bit.GPIO27 = 2; // I2CA_SCL
GpioCtrlRegs.GPAMUX2.bit.GPIO27 = 3;
GpioCtrlRegs.GPAQSEL2.bit.GPIO27 = 3; // Input qualification : Asynchronous
GpioCtrlRegs.GPAPUD.bit.GPIO27 = 0; // Pull up enable
GpioCtrlRegs.GPBGMUX2.bit.GPIO56 = 0; // IRQ_1
GpioCtrlRegs.GPBMUX2.bit.GPIO56 = 0;
GpioCtrlRegs.GPBGMUX1.bit.GPIO34 = 0; // ADC_RST
GpioCtrlRegs.GPBGMUX1.bit.GPIO34 = 0;
GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // Direction as output
EDIS;
GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1; // ADC held at reset state
I2caRegs.I2CMDR.bit.IRS = 0; // I2C is disabled
I2caRegs.I2CPSC.bit.IPSC = 9; // System clock divider value
I2caRegs.I2CCLKL = 95; // Low time divider
I2caRegs.I2CCLKH = 95; // High time divider
I2caRegs.I2CMDR.bit.MST = 1; // Master mode
I2caRegs.I2CMDR.bit.TRX = 1; // Transmitter mode
I2caRegs.I2CMDR.bit.BC = 0; // 8 bits per data byte
I2caRegs.I2CCNT = 2; // Data count
I2caRegs.I2CSAR.bit.SAR = 0x40; // Slave address register
I2caRegs.I2COAR.bit.OAR = 0x3C; // I2C own address register
I2caRegs.I2CMDR.bit.DLB = 0; // Digital loop back disabled
I2caRegs.I2CMDR.bit.FREE = 1; // I2C runs in free mode
I2caRegs.I2CMDR.bit.IRS = 1; // I2C is enabled
GpioDataRegs.GPBSET.bit.GPIO34 = 1; // ADC released from reset state
DELAY_US(1);
I2caRegs.I2CMDR.bit.STT = 1; // Generate start signal
I2caRegs.I2CDXR.bit.DATA = 0x80; // Slave address and WRITE bit
I2caRegs.I2CDXR.bit.DATA = 0x06; // RESET command
DELAY_US(10);
I2caRegs.I2CMDR.bit.STP = 1; // Generate stop signal
DELAY_US(10);
I2caRegs.I2CMDR.bit.STT = 1; // Generate start signal
I2caRegs.I2CDXR.bit.DATA = 0x80; // Slave address and WRITE bit
I2caRegs.I2CDXR.bit.DATA = 0x44; // WREG command and Configuration register 1 address
I2caRegs.I2CDXR.bit.DATA = 0x02; // CR 1 data
I2caRegs.I2CMDR.bit.STP = 1; // Generate stop signal
DELAY_US(10);
I2caRegs.I2CMDR.bit.STT = 1; // Generate start signal
I2caRegs.I2CDXR.bit.DATA = 0x80; // Slave address and WRITE bit
I2caRegs.I2CMDR.bit.STT = 1; // Generate start signal
I2caRegs.I2CDXR.bit.DATA = 0x24; // RREG command and CR 1 address
I2caRegs.I2CMDR.bit.STT = 1; // Generate start signal
DELAY_US(10);
I2caRegs.I2CMDR.bit.STT = 1; // Generate start signal
I2caRegs.I2CDXR.bit.DATA = 0x81; // Slave address and READ bit
I2caRegs.I2CMDR.bit.STP = 1; // Generate stop signal
r1 = I2caRegs.I2CDRR.bit.DATA; // Data receive operation
for(;;)
{
}
}
The following are the scope shots I obtained while executing the above code
The above scope shot is obtained when I executed step (1) in the code. Slave address with write bit 0x80 and is acknowledged by the slave successfully.
The above scope shot is obtained when I executed step (2) in the code. Slave address with write bit 0x80 for initiating a RESET command to first slave. But at this point I am not receiving an acknowledgement but the same slave acknowledged to START signal in the previous step. After this step (2) I am not obtaining any response on the scope. Why this is happening?
And if there is anything I can look into for a better understanding of I2C coding please let me know.
* I have checked for both slaves 0x40, 0x41 both these salves acknowledge to START then there is no response from them.
* Also checked with an invalid address which returned NACK to START command itself.
Thank you,
Vineeth






