我有一个tiva c微控制器tm4c123gxl
我已经尝试了一段时间使用电路板上的I2C
模块和数字accelrometer没有结果,我一直在努力将MDR
寄存器设置为要发送的特定值,但保持为0
这里是我用于初始化的代码,直到达到我使用逐步调试设置MDR寄存器的部分我最初运行代码到I2C3_MDR_R = 0x2D;
的分配步骤
void PortDInit(void)
{
volatile unsigned long delay=0;
SYSCTL_RCGCI2C_R|=0x8; //1-set clock of I2C of module 3
delay = SYSCTL_RCGC2_R; //2-delay to allow clock to stabilize
SYSCTL_RCGC2_R |= 0x00000008; //3-port D clock
delay = SYSCTL_RCGC2_R; //4-delay to allow clock to stabilize
GPIO_PORTD_AFSEL_R |= 0x03; //5-alternate function set for I2C mode
GPIO_PORTD_DEN_R |=0x03; //6-enable digital functionality for PA6 and PA7
GPIO_PORTD_ODR_R|=0x02; //7-enable open drain mode for I2CSDA register of port A
GPIO_PORTD_PCTL_R = 0x00000033; //8-set PCTL to I2C mode
I2C3_MCR_R= 0x00000010; // 9-intialize the i2c master
I2C3_MTPR_R = 0x00000007; // 10-number of system clock cycles in 1 scl period
I2C3_MSA_R = 0x3A // set slave address and read write bit
I2C3_MDR_R = 0x2D; // data to be sent BREAK POINT HERE using single step here yields MDR with same value = 0
I2C3_MCS_R = 0x00000003; // follow transmit condition
while(I2C3_MCS_R &= 0x40 == 1); // wait bus is busy sending data
if(I2C3_MCS_R&=0x04 ==1)
{
//handle error in communication
}
else
{
//success in transmission
}
我为达到此代码所做的工作
希望任何人都有所帮助 感谢。
答案 0 :(得分:0)
这是一个很长的镜头,但是这里有:
在您的评论中,第6步说
//6-enable digital functionality for PA6 and PA7
但似乎您正在使用GPIO_PORTD ...
也许是评论拼写错误(你的意思是PD6和PD7) 但只是仔细检查你正在看正确的针......
祝你好运!