Part Number: TMS320F28035
Other Parts Discussed in Thread: C2000WARE
Tool/software: Code Composer Studio
hi
I have set an I2C slave on the TMS320F28035, but it doesn`t work. The master cannot find a slave on the bus. And, I did not find the relevant examples. I don't know if my program structure is correct. So, I am asking for help in the forum.
Thanks
the mian function:
/*
* main.c
*/
#include "DSP28x_Project.h"
#include "DSP2803x_I2c.h"
#include "DSP2803x_I2c_defines.h"
#include <math.h>
#define I2C_slave_addr 0x08
#define LED_ON GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
#define LED_OFF GpioDataRegs.GPBSET.bit.GPIO34 = 1;
#define LED_BLINK GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;
struct I2C_REGS I2c_slave;
int read=0;
int count=0;
void I2C_Slave_Init(void);
int I2C_Slave_read(void);
int main(void)
{
InitSysCtrl();
InitGpio();
InitI2CGpio();
I2C_Slave_Init();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
// InitPeripherals();
while(1)
{
read=I2C_Slave_read();
if (read == 0x0001)
{
LED_OFF;
}
else
{
LED_ON;
}
}
}
void I2C_Slave_Init(void)
{
I2c_slave.I2COAR = 0x0010; // Set Own Adress
I2c_slave.I2CMDR.all = 0x0000;
I2c_slave.I2CPSC.all = 19; // Prescaler - need 7-12 Mhz on module clk
I2c_slave.I2CCLKL = 10; // NOTE: must be non zero
I2c_slave.I2CCLKH = 5; // NOTE: must be non zero
I2c_slave.I2CIER.all = 0x0; // disable SCD & ARDY __interrupts
I2c_slave.I2CFFTX.all = 0x0000; // Enable FIFO mode and TXFIFO
I2c_slave.I2CFFRX.all = 0x0000; // Enable RXFIFO, clear RXFFINT,
I2c_slave.I2CMDR.all = 0x0020; // I2C Slave, Free, release from reset
return;
}
int I2C_Slave_read(void)
{
int i;
I2c_slave.I2CCNT=1;
// I2c_slave.I2COAR=I2C_slave_addr;
// I2c_slave.I2CSAR=I2C_slave_addr;
// I2c_slave.I2CMDR.all=0x6c20;
i = I2c_slave.I2CDRR & 0x00FF;//I2CDRR is a 16 bit register,
return i;
// receivedata[0]=I2c_slave.I2CDRR;
}