完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
可不可以直接用i2c向外面按照协议格式一直发数据,需要有什么方面的配置。为什么我的配置之后只能发送地址信息,然后就结束了。。。。。小白求帮助。
/* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup Template_Project * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ static __IO uint32_t TimingDelay; RCC_ClocksTypeDef RCC_Clocks; __IO uint16_t sEEAddress = 0x44; //__IO uint32_t sEETimeout = sEE_LONG_TIMEOUT; __IO uint16_t sEEDataNum; __IO uint32_t sEETimeout; __IO uint32_t sEETrials = 0; #define sEE_WRITE_ADDRESS1 0x00 #define sEE_READ_ADDRESS1 0x00 #define BUFFER_SIZE1 256 #define BUFFER_SIZE2 256 #define sEE_WRITE_ADDRESS2 (sEE_WRITE_ADDRESS1 + BUFFER_SIZE1) #define sEE_READ_ADDRESS2 (sEE_READ_ADDRESS1 + BUFFER_SIZE1) //状态变量 typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus; /* Private functions ---------------------------------------------------------*/ /** * @brief Main program. * @param None * @retval None */ void main(void) { uint8_t senddata=0xa0; GPIO_InitTypeDef GPIO_InitStructure; I2C_InitTypeDef I2C_InitStruct; // 配置I2C始终资源 RCC_I2CCLKConfig(RCC_I2C1CLK_HSI); //GPIO使能 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); //IIC使能 RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); //GPIO管脚配置 GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_1); GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_1); GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_1); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_1; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin =GPIO_Pin_7; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin =GPIO_Pin_5; GPIO_Init(GPIOB,&GPIO_InitStructure); /* I2C configuration */ I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; I2C_InitStruct.I2C_AnalogFilter = I2C_AnalogFilter_Enable; I2C_InitStruct.I2C_DigitalFilter = 0x00; I2C_InitStruct.I2C_OwnAddress1 =0x00; // I2C_InitStruct.I2C_Ack = I2C_Ack_Enable; I2C_InitStruct.I2C_Ack = I2C_Ack_Disable; I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStruct.I2C_Timing =0x00210507;//100Kbits I2C_Init(I2C1, &I2C_InitStruct); //I2C_SMBusAlertCmd(I2C1,ENABLE); I2C_Cmd(I2C1, ENABLE); while(1) { I2C_TransferHandling(I2C1, sEEAddress, 2, I2C_Reload_Mode, I2C_Generate_Start_Write); I2C_SendData(I2C1,senddata); } } /** * @brief Inserts a delay time. * @param nTime: specifies the delay time length, in 10 ms. * @retval None */ void Delay(__IO uint32_t nTime) { TimingDelay = nTime; while(TimingDelay != 0); } /** * @brief Decrements the TimingDelay variable. * @param None * @retval None */ void TimingDelay_Decrement(void) { if (TimingDelay != 0x00) { TimingDelay--; } } /** * @} */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
|
相关推荐
21个回答
|
|
|
不错的经验,感谢分享,学习中
|
|
|
|
|
|
不错,很好的经验分享,辛苦麻烦了,欠缺这方面的资料,非常感谢。
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
STM32F405驱动DS1302时钟模块,输出时间错乱该怎么排查?
2810 浏览 2 评论
stm32f405rgt6驱动DS1302ZN出现时间错乱问题
2420 浏览 1 评论
stm32用fsmc读取ad7606采集数据,数据不变,只有开发版复位才更新数据
2288 浏览 0 评论
2404 浏览 1 评论
1643 浏览 1 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 12:46 , Processed in 0.612197 second(s), Total 75, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1573