你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【STM8-SO8-DISCO】——10、串口打印EEPROM数据

[复制链接]
七哥 发布时间:2019-3-12 01:06
【STM8-SO8-DISCO】——10、串口打印EEPROM数据


  本贴在前贴的基础上,添加了串口打印EEPROM数据。
前贴链接:
【STM8-SO8-DISCO】——9、字节方式读写EEPROM
https://www.stmcu.org.cn/module/forum/forum.php?mod=viewthread&tid=619717&fromuid=307297
串口打印功能请参考:
【STM8-SO8-DISCO】——8、测试 UART1_Printf
https://www.stmcu.org.cn/module/forum/forum.php?mod=viewthread&tid=619620&fromuid=307297

  主函数main()实现。
  1. void main(void)
  2. {
  3.   uint8_t i = 0;   
  4.   uint8_t dir = 0;

  5.   STARTUP_SWIM_DELAY_5S;

  6.   /* Clock configuration -----------------------------------------*/
  7.   CLK_Config();

  8.   /* GPIO Configuration ------------------------------------------*/
  9.   GPIO_Config();  

  10.   /* FLASH Configuration ------------------------------------------*/
  11.   FLASH_Config();
  12.   
  13.   UART1_DeInit();
  14.   /* UART1 configuration ------------------------------------------------------*/
  15.   /* UART1 configured as follow:
  16.         - BaudRate = 115200 baud  
  17.         - Word Length = 8 Bits
  18.         - One Stop Bit
  19.         - No parity
  20.         - Receive and transmit enabled
  21.         - UART1 Clock disabled
  22.   */
  23.   UART1_Init((uint32_t)115200, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO,
  24.               UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);

  25.   /* Output a message on Hyperterminal using printf function */
  26.   printf("\n\rUART1 Example :retarget the C library printf()/getchar() functions to the UART\n\r");
  27.   printf("EEPROM Test!\n\r");
  28.   
  29.   /* ********************************************************************* */
  30.   printf("Read from EEPROM Start:\n\r");  
  31.   /* Fill the buffer with EEPROM Data */
  32.   for (i=0;i<128;i++)
  33.   {
  34.     /* Read byte at a specified address i */
  35.     GBuffer[i] = FLASH_ReadByte(EEPROM_BASE_ADDR+i);
  36.   }
  37.   
  38.   if (GBuffer[0] == 0x00)
  39.     dir = 1;
  40.   else
  41.     dir = 0;
  42.   
  43.   for (i = 0; i < 128; i++)
  44.   {
  45.     printf("0x%02x,", GBuffer[i] );
  46.     if ((i+1)%16 == 0)
  47.       printf("\n\r");
  48.   }
  49.   printf("Reading End!\n\r");
  50.   
  51.   /* ********************************************************************* */
  52.   printf("Write EEPROM Start:\n\r");  
  53.   for (i=0;i<128;i++)
  54.   {
  55.     if (dir == 0)
  56.       /* Write byte at a specified address i */
  57.       FLASH_ProgramByte((EEPROM_BASE_ADDR+i),i);
  58.     else
  59.       /* Write byte at a specified address i */
  60.       FLASH_ProgramByte((EEPROM_BASE_ADDR+i),i+128);   
  61.   }
  62.   
  63.   /* Fill the buffer with EEPROM Data */
  64.   for (i=0;i<128;i++)
  65.   {
  66.     /* Read byte at a specified address i */
  67.     GBuffer[i] = FLASH_ReadByte(EEPROM_BASE_ADDR+i);
  68.   }
  69.   
  70.   for (i = 0; i < 128; i++)
  71.   {
  72.     printf("0x%02x,", GBuffer[i] );
  73.     if ((i+1)%16 == 0)
  74.       printf("\n\r");
  75.   }  
  76.   printf("Writting End!\n\r");
  77.   
  78.   /* ********************************************************************* */
  79.   
  80.   while (1)
  81.   {   
  82.     GPIO_WriteReverse(LED_GPIO_PORT, (GPIO_Pin_TypeDef)LED_GPIO_PINS);
  83.     Delay(0xFFFF);
  84.   }
  85. }
复制代码

  程序功能与前贴相似,只不过原来由打断点观察内存及变量,改为了从上位机串口助手观察。

  实验连线如下图
01.jpg

  第一次上电,串口打印内容。
11.jpg

  第二次上电,串口打印内容。
12.jpg

  首先读取全部128字节EEPROM中的数据,打印到串口;然后修改EEPROM内容,再次从EEPROM读取全部数据,并打印。
  程序中判断EEPROM中第一个字节是否等于0x00,如果等于0x00,则往EEPROM中写入内容0x80到0xFF;如果不等于0x00,则往EEPROM写入0x00到0x7F。每次上电,EEPROM中内容都会修改一次。

  至此,通过串口打印EEPROM内容实验完成。
  本贴测试工程附上:
   STM8S_StdPeriph_Flash_EEPROM_Printf.rar (268.3 KB, 下载次数: 26)
收藏 1 评论6 发布时间:2019-3-12 01:06

举报

6个回答
qytcs 回答时间:2019-6-10 10:58:12
学习学习
唐英tcy 回答时间:2019-6-13 19:06:19
谢谢分享
qytcs 回答时间:2019-6-17 16:14:34
学习学习
TEACHER33 回答时间:2019-6-21 21:29:24
谢谢分享
engerHi 回答时间:2019-7-8 00:22:32
这些日子正在搞8S的芯片,有点启发性的都下下来看一下,谢谢楼主!
yf14789652 回答时间:2020-1-7 08:24:36
学习一下串口打印 数字要怎么调配。
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版