完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
1. 修改usart.c,将printf转为串口打印 /* USER CODE BEGIN 0 */ #include "stdio.h" int fputc(int ch, FILE *f) { /* Place your implementation of fputc here */ /* e.g. write a character to the USART2 and Loop until the end of transmission */ HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); return ch; } /* USER CODE END 0 */ 2.修改i2c.c void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(i2cHandle->Instance==I2C1) { /* USER CODE BEGIN I2C1_MspInit 0 */ /* USER CODE END I2C1_MspInit 0 */ __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_I2C1_CLK_ENABLE(); /**I2C1 GPIO Configuration PB6 ------> I2C1_SCL PB7 ------> I2C1_SDA */ GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* I2C1 clock enable */ /* USER CODE BEGIN I2C1_MspInit 1 */ /* USER CODE END I2C1_MspInit 1 */ } } 3.修改main.c 增加头文件: #include "main.h" #include "i2c.h" #include "usart.h" #include "gpio.h" #include #include /* USER CODE BEGIN 1 */ #define ADDR_24LCxx_Write 0xA0 #define ADDR_24LCxx_Read 0xA1 #define BufferSize 256 uint8_t WriteBuffer[256] = { 0 }; uint8_t ReadBuffer[256] = { 0 }; uint16_t i = 0; /* USER CODE END 1 */ /* USER CODE BEGIN 2 */ printf("rn***************I2C Example00*******************************rn"); HAL_StatusTypeDef status = HAL_OK; for(i=0; i<256; i++) { WriteBuffer=i; /* WriteBuffer Initialization */ printf("%02d ", WriteBuffer); } unsigned int iPageSize = 8; for(i=0; i<256/iPageSize; i++) { if (HAL_I2C_Mem_Write(&hi2c1, ADDR_24LCxx_Write, i*iPageSize, I2C_MEMADD_SIZE_16BIT,&(WriteBuffer[i*iPageSize]),iPageSize, 1000) == HAL_OK) { //printf("rn Byte %02d to Byte %02d Write OK",i,i+8); HAL_Delay(5);//写完以后需要延时5ms,这个不能少 }else{ //printf("rn Byte %02d to Byte %02d Write Failed",i,i+8); } } /* read date from EEPROM */ status = HAL_I2C_Mem_Read(&hi2c1, ADDR_24LCxx_Read, 0, I2C_MEMADD_SIZE_16BIT,ReadBuffer,BufferSize, 0x1000); printf("%drn",status); for(i=0; i<256; i++) printf("%02d ",ReadBuffer); if(memcmp(ReadBuffer,WriteBuffer,256) == 0 ) /* check data */ printf("rn AT24C02 Read Test OKrn"); else printf("rn AT24C02 Read Test Failedrn"); /* USER CODE END 2 */ |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1780 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1621 浏览 1 评论
1081 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
728 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1679 浏览 2 评论
1938浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
731浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
570浏览 3评论
596浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
556浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 03:51 , Processed in 1.016539 second(s), Total 78, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号