在TMS320F28035上建立I2C_slave时,无法工作

我在TMS320F28035上搭建了一个I2C的从机,但是,无法实现功能,也没有找到相关的官方例程。如果有人在这方面有过经验,想请您给出点建议,谢谢。我的代码如下:

/*
* 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);
void I2C_Slave_write(int returnvalue);

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;
i = I2c_slave.I2CDRR & 0x00FF;//I2CDRR is a 16 bit register,
return i;
// receivedata[0]=I2c_slave.I2CDRR;
}

void I2C_Slave_write(int returnvalue)
{

}

2 个回复