用TMS320F28x的DSP中的I2C向外输出数据都需要做哪些设置?

martenyong 2011-10-12 02:26:10
用TMS320F28x的DSP中的I2C向外输出数据,只写不读,不用中断的形式,而是发命令让它向外写数据,都需要做哪些设置?
谢谢!
...全文
369 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Peasant_Lee 2011-10-13
  • 打赏
  • 举报
回复
我以前用过55系列的。。。SCL会被拉低,,,假如你确保软件没有问题,那会不会你的硬件上面出问题了呢?SCL线的连接到对方,对方的引脚配置错了,搞为低电平了,或者线路上一些问题。
zhujie0128 2011-10-13
  • 打赏
  • 举报
回复
学习了
martenyong 2011-10-13
  • 打赏
  • 举报
回复
以下是写数据的函数,是TI提供的例程
Uint16 I2CA_WriteData(struct I2CMSG *msg)
{
Uint16 i;

// Wait until the STP bit is cleared from any previous master communication.
// Clearing of this bit by the module is delayed until after the SCD bit is
// set. If this bit is not checked prior to initiating a new message, the
// I2C could get confused.
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}

// Setup slave address
I2caRegs.I2CSAR = msg->SlaveAddress;

// Check if bus busy
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}

// Setup number of bytes to send
// MsgBuffer + Address
I2caRegs.I2CCNT = msg->NumOfBytes+2;

// Setup data to send
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
// for (i=0; i<msg->NumOfBytes-2; i++)
for (i=0; i<msg->NumOfBytes2; i++)

{
I2caRegs.I2CDXR = *(msg->MsgBuffer+i);
}

// Send start as master transmitter
I2caRegs.I2CMDR.all = 0x6E20;

return I2C_SUCCESS;
}


我调用的时候是这样的:
 //first clear the STP
I2caRegs.I2CMDR.bit.STP = 0;
wait_1us();
while(I2caRegs.I2CSTR.bit.BB == 1)
{
I2caRegs.I2CSTR.bit.BB = 0;
wait_1us();
}
// Check the outgoing message to see if it should be sent.
// In this example it is initialized to send with a stop bit.
if(I2cMsgOut1.MsgStatus == I2C_MSGSTAT_SEND_WITHSTOP)
{
Error = I2CA_WriteData(&I2cMsgOut1);
// If communication is correctly initiated, set msg status to busy
// and update CurrentMsgPtr for the interrupt service routine.
// Otherwise, do nothing and try again next loop. Once message is
// initiated, the I2C interrupts will handle the rest. Search for
// ICINTR1A_ISR in the i2c_eeprom_isr.c file.
if (Error == I2C_SUCCESS)
{
CurrentMsgPtr = &I2cMsgOut1;
I2cMsgOut1.MsgStatus = I2C_MSGSTAT_WRITE_BUSY;
}
} // end

I2caRegs.I2CMDR.bit.STP = 1;
while(I2caRegs.I2CSTR.bit.BB == 0)
{
I2caRegs.I2CSTR.bit.BB = 1;
wait_1us();
}

现在程序运行的情况是SCL会被拉低,数据无法写入LTC2635,且运行后SCL无法被拉高,请问有用过这个芯片做过开发的么?应该怎么处理呢,谢谢了!
martenyong 2011-10-13
  • 打赏
  • 举报
回复
目前的问题是 ,我调用了函数之后,SCL脚就被拉低,但是数据写不进去。以下是初始化程序
//I2c init
void I2CA_Init(void)
{
// Initialize I2C
// I2caRegs.I2CSAR = 0x0050; // Slave address - EEPROM control code
I2caRegs.I2CSAR = 0x0010; // Slave address - EEPROM control code for LTC2635

// I2CCLK = SYSCLK/(I2CPSC+1)
#if (CPU_FRQ_40MHZ||CPU_FRQ_50MHZ)
I2caRegs.I2CPSC.all = 4; // Prescaler - need 7-12 Mhz on module clk
#endif

#if (CPU_FRQ_60MHZ)
I2caRegs.I2CPSC.all = 6; // Prescaler - need 7-12 Mhz on module clk
#endif
I2caRegs.I2CCLKL = 10; // NOTE: must be non zero
I2caRegs.I2CCLKH = 5; // NOTE: must be non zero
// I2caRegs.I2CIER.all = 0x24; // Enable SCD & ARDY interrupts
I2caRegs.I2CIER.all = 0; // Disable SCD & ARDY interrupts

I2caRegs.I2CMDR.all = 0x0020; // Take I2C out of reset
// Stop I2C when suspended

I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO
I2caRegs.I2CFFRX.all = 0x2040; // Enable RXFIFO, clear RXFFINT,

return;
}

请问有问题么?
Peasant_Lee 2011-10-13
  • 打赏
  • 举报
回复
那就确定是软件问题了,要一点点的排查一下才行了。应该某个配置的地方,出现了疏忽,我没有用过28xx的,也没有对应的代码,所以看代码的话,我也看不出什么所以然来,呵呵。
martenyong 2011-10-13
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 peasant_lee 的回复:]

我以前用过55系列的。。。SCL会被拉低,,,假如你确保软件没有问题,那会不会你的硬件上面出问题了呢?SCL线的连接到对方,对方的引脚配置错了,搞为低电平了,或者线路上一些问题。
[/Quote]

我试过TI给的例程,就是用中断模式编写的,SCL和SDA都是好用的,但是没法写进去数据。
自己改了之后,SCL和SDA就不怎么正常了。
woshi_ziyu 2011-10-12
  • 打赏
  • 举报
回复
把I2C写命令写到一个函数 然后需要的时候调用就行呢
Peasant_Lee 2011-10-12
  • 打赏
  • 举报
回复
只写不读的话,省很多寄存器的配置了,配置好起始,停止,应答,等相关的时序机制就OK了,当然ICC的数据寄存器,发送寄存器也要填数据。然后就可以启动了。具体 的话datasheet会有相关说明的了

27,373

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 单片机/工控
社区管理员
  • 单片机/工控社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧