我有一个tm4c123gxl微控制器,我已经尝试了一段时间使用电路板上的I2C模块,但没有结果,我一直在尝试用一定的值设置MDR寄存器,但它保持为0。
下面是我用于初始化的代码,直到到达我设置MDR寄存器im的部分--使用逐步调试--我最初将代码运行到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
}我为达到这个代码所做的一切
希望有人能帮忙谢谢。
发布于 2016-12-18 06:25:15
这是一个很长的机会,但这里说:
在你的评论中,第6步说
//6-enable digital functionality for PA6 and PA7但看来你在研究GPIO_PORTD..。
也许这是一个注释错误(您的意思是PD6和PD7),但是请再次检查一下您正在查看的是正确的引脚.
祝好运!
https://stackoverflow.com/questions/40751185
复制相似问题