完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
刚入手am335x(祼机),想利用I2C2来获取当前的时间。代码如下,问题是它发送主机地址时,它一直没有一个应答,一直卡在发送过程中,麻烦请指点一下,谢谢。
main()[ I2CAintcConfigure(); SetupI2C(); configData = 0xA2 ; ConfiguretimeSensor(configData); ptrReg = 0x02; TemperatureRegRead(temperature, ptrReg); ] static void SetupI2C(void) [ // I2C1ModuleClkConfig(); // I2C2 clk module I2C2ModuleClkConfig(); I2CPinMuxSetup(2); /* Put i2c in reset/disabled state */ I2CMasterDisable(SOC_I2C_2_REGS); /* ** Upon reset Auto Idel is enabled. ** Hence it is disabled after reset */ I2CAutoIdleDisable(SOC_I2C_2_REGS); /* Configure i2c bus speed to 400khz */ I2CMasterInitExpClk(SOC_I2C_2_REGS, 48000000, 12000000, 400000); /* Set i2c slave address */ I2CMasterSlaveAddrSet(SOC_I2C_2_REGS, I2C_SLAVE_ADDR); //0xA2 /* Bring I2C module out of reset */ I2CMasterEnable(SOC_I2C_2_REGS); ] void I2CPinMuxSetup(unsigned int instance) [ if(instance == 0) [ HWREG(SOC_CONTROL_REGS + CONTROL_CONF_I2C0_SDA) = (CONTROL_CONF_I2C0_SDA_CONF_I2C0_SDA_RXACTIVE | CONTROL_CONF_I2C0_SDA_CONF_I2C0_SDA_SLEWCTRL | CONTROL_CONF_I2C0_SDA_CONF_I2C0_SDA_PUTYPESEL ); HWREG(SOC_CONTROL_REGS + CONTROL_CONF_I2C0_SCL) = (CONTROL_CONF_I2C0_SCL_CONF_I2C0_SCL_RXACTIVE | CONTROL_CONF_I2C0_SCL_CONF_I2C0_SCL_SLEWCTRL | CONTROL_CONF_I2C0_SCL_CONF_I2C0_SCL_PUTYPESEL ); ] else if(instance == 1) [ /* I2C_SCLK */ HWREG(SOC_CONTROL_REGS + CONTROL_CONF_SPI0_D1) = (CONTROL_CONF_SPI0_D1_CONF_SPI0_D1_PUTYPESEL | CONTROL_CONF_SPI0_D1_CONF_SPI0_D1_RXACTIVE | CONTROL_CONF_SPI0_D1_CONF_SPI0_D1_SLEWCTRL | CONTROL_CONF_MUXMODE(2)); /* I2C_SDA */ HWREG(SOC_CONTROL_REGS + CONTROL_CONF_SPI0_CS0) = (CONTROL_CONF_SPI0_CS0_CONF_SPI0_CS0_PUTYPESEL | CONTROL_CONF_SPI0_CS0_CONF_SPI0_CS0_RXACTIVE | CONTROL_CONF_SPI0_D1_CONF_SPI0_D1_SLEWCTRL | CONTROL_CONF_MUXMODE(2)); ] else if(instance == 2) [ /* I2C_SCLK */ HWREG(SOC_CONTROL_REGS + CONTROL_CONF_UART_RTSN(1)) = (CONTROL_CONF_SPI0_D1_CONF_SPI0_D1_PUTYPESEL | CONTROL_CONF_SPI0_D1_CONF_SPI0_D1_RXACTIVE | CONTROL_CONF_SPI0_D1_CONF_SPI0_D1_SLEWCTRL | CONTROL_CONF_MUXMODE(2)); /* I2C_SDA */ HWREG(SOC_CONTROL_REGS + CONTROL_CONF_UART_CTSN(1)) = (CONTROL_CONF_SPI0_CS0_CONF_SPI0_CS0_PUTYPESEL | CONTROL_CONF_SPI0_CS0_CONF_SPI0_CS0_RXACTIVE | CONTROL_CONF_SPI0_D1_CONF_SPI0_D1_SLEWCTRL | CONTROL_CONF_MUXMODE(2)); ] ] /* ** I2C Interrupt Service Routine. This function will read and write ** data through I2C bus. */ void I2CIsr(void) [ unsigned int status = 0; /* Get only Enabled interrupt status */ status = I2CMasterIntStatus(SOC_I2C_2_REGS); /* ** Clear all enabled interrupt status except receive ready and ** transmit ready interrupt status */ I2CMasterIntClearEx(SOC_I2C_2_REGS, (status & ~(I2C_INT_RECV_READY | I2C_INT_TRANSMIT_READY))); if(status & I2C_INT_RECV_READY) [ /* Receive data from data receive register */ dataFromSlave[rCount++] = I2CMasterDataGet(SOC_I2C_2_REGS); /* Clear receive ready interrupt status */ I2CMasterIntClearEx(SOC_I2C_2_REGS, I2C_INT_RECV_READY); if(rCount == numOfBytes) [ /* Disable the receive ready interrupt */ I2CMasterIntDisableEx(SOC_I2C_2_REGS, I2C_INT_RECV_READY); /* Generate a STOP */ I2CMasterStop(SOC_I2C_2_REGS); ] ] if (status & I2C_INT_TRANSMIT_READY) [ /* Put data to data transmit register of i2c */ I2CMasterDataPut(SOC_I2C_2_REGS, dataToSlave[tCount++]); /* Clear Transmit interrupt status */ I2CMasterIntClearEx(SOC_I2C_2_REGS, I2C_INT_TRANSMIT_READY); if(tCount == numOfBytes) [ /* Disable the transmit ready interrupt */ I2CMasterIntDisableEx(SOC_I2C_2_REGS, I2C_INT_TRANSMIT_READY); ] ] if (status & I2C_INT_STOP_CONDITION) [ /* Disable transmit data ready and receive data read interupt */ I2CMasterIntDisableEx(SOC_I2C_2_REGS, I2C_INT_TRANSMIT_READY | I2C_INT_RECV_READY | I2C_INT_STOP_CONDITION); flag = 0; ] if(status & I2C_INT_NO_ACK) [ I2CMasterIntDisableEx(SOC_I2C_2_REGS, I2C_INT_TRANSMIT_READY | I2C_INT_RECV_READY | I2C_INT_NO_ACK | I2C_INT_STOP_CONDITION); /* Generate a STOP */ I2CMasterStop(SOC_I2C_2_REGS); flag = 0; ] ] static void ConfigureTimeSensor(unsigned char configData) [ dataToSlave[0] = configData; tCount = 0; SetupI2CTransmit(1); ] /* Reads temperature value */ static void TemperatureRegRead(unsigned char *data, unsigned char ptrReg) [ unsigned int i; rCount = 0; tCount = 0; /* Reg offset of temperature sensor */ dataToSlave[0] = ptrReg; SetupI2CReception(7); for(i = 7; i ; i--) [ *data = dataFromSlave[7-i]; data++; ] ] |
|
相关推荐
4 个讨论
|
|
只有小组成员才能发言,加入小组>>
332 浏览 1 评论
528 浏览 2 评论
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
772 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
649 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1124 浏览 1 评论
AT32F407在USART2 DMA发送数据时,接包接到了要发送的数据,程序还是处于等待传输完成的标识判断中,为什么?
54浏览 29评论
90浏览 23评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
248浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
196浏览 14评论
两个TMP117传感器一个可以正常读取温度值,一个读取的值一直是0,为什么?
54浏览 13评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 19:22 , Processed in 0.528378 second(s), Total 44, Slave 38 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号