[单片机芯片] 【CH32X035评估板测评】PIOC测试

[复制链接]
 楼主| 90houyidai 发表于 2023-10-16 22:11 | 显示全部楼层 |阅读模式
手里有个活,需要点一个2812的灯环,正好碰上了CH32X035评估板测评
根据手册提到有 可编程协议I/O控制器PIOC,可实现最多2个I/O引脚的协议控制,支持1024个WS2812等型号的单线RGB芯片串接
这个内置的控制器还是第一次接触
按照提供的例程稍微修改,将关于1820单总线的代码剔除后测试
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name          : main.c
  3. * Author             : WCH
  4. * Version            : V1.0.0
  5. * Date               : 2023/04/06
  6. * Description        : Main program body.
  7. *********************************************************************************
  8. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  9. * Attention: This software (modified or not) and binary are used for
  10. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  11. *******************************************************************************/

  12. /* 1-wire example: 1W-RGB_WS2812, 1W-DS1820
  13. * PC18 or PC7 needs to connected  a 4.7k pull-up resistor when chip drives DS1820 mode.
  14. * RAM--
  15. *  PIOC-4K
  16. *  User-16K
  17. */

  18. #include "debug.h"
  19. #include "RGB1W.h"

  20. #define RGB    0
  21. #define RGB_LED_NUM 48
  22. #define Mode   RGB_WS2812

  23. __IO        uint16_t        temper;

  24. u8 RGBpbuf[] = {
  25.     0xFF, 0x00, 0x00,
  26.     0x00, 0xFF, 0x00,
  27.     0x00, 0x00, 0xFF,
  28.     0xFF, 0x00, 0x00,
  29.     0x00, 0xFF, 0x00,
  30.     0x00, 0x00, 0xFF,
  31.     0xFF, 0x00, 0x00,
  32.     0x00, 0xFF, 0x00,
  33.     0x00, 0x00, 0xFF,
  34.     0xFF, 0x00, 0x00,
  35. };

  36. u8 RGBpbuf1[] = {
  37.      0x00, 0xFF, 0x00,
  38.      0x00, 0x00, 0xFF,
  39.      0xFF, 0x00, 0x00,
  40.      0x00, 0xFF, 0x00,
  41.      0x00, 0x00, 0xFF,
  42.      0xFF, 0x00, 0x00,
  43.      0x00, 0xFF, 0x00,
  44.      0x00, 0x00, 0xFF,
  45.      0xFF, 0x00, 0x00,
  46.      0x00, 0xFF, 0x00,
  47. };

  48. u8 RGBpbuf2[] = {
  49.      0x00, 0xFF, 0x00,
  50.      0x00, 0x00, 0xFF,
  51.      0xFF, 0x00, 0x00,
  52.      0x00, 0xFF, 0x00,
  53.      0x00, 0x00, 0xFF,
  54.      0xFF, 0x00, 0x00,
  55.      0x00, 0xFF, 0x00,
  56.      0x00, 0x00, 0xFF,
  57.      0xFF, 0x00, 0x00,
  58.      0x00, 0xFF, 0x00,
  59. };

  60. /* Global define */
  61. #define     rgb_source_addr         ((uint8_t *)RGBpbuf2)
  62. #define     rgb_data_bytes          (RGB_LED_NUM*3)    // 10 RGB LEDs, 30 bytes data
  63. #define     timer_to_run            1   // start by timer

  64. u8 RGBpbuf3[rgb_data_bytes];
  65. void rgb_all_led(u8 color_r,u8 color_g,u8 color_b);
  66. void rgb_set_pixel(u8 n,u8 color_r,u8 color_g,u8 color_b);
  67. /*********************************************************************
  68. * @fn      main
  69. *
  70. * [url=home.php?mod=space&uid=247401]@brief[/url]   Main program.
  71. *
  72. * [url=home.php?mod=space&uid=266161]@return[/url]  none
  73. */
  74. int main(void)
  75. {
  76.     uint16_t    total_bytes;
  77.         uint8_t     t1=0;
  78.         u8* RGB_RAM;


  79.     Delay_Init();
  80.     Delay_Ms(1000);
  81.     Delay_Ms(1000);
  82.     USART_Printf_Init(115200);
  83.     printf("SystemClk:%d\r\n", SystemCoreClock);
  84.     printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );

  85.         RGB1W_Init( );
  86.         stat = 0x80;    //free

  87.         while ( 1 )
  88.         {
  89.            total_bytes = rgb_data_bytes;
  90. //        rgb_all_led(23,23,70);
  91. ////        rgb_set_pixel(1,5,100,50);
  92. //        RGB_RAM = RGBpbuf3;
  93. //        RGB1W_SendRAM_Wait( rgb_data_bytes, RGB_RAM );
  94. //        Delay_Ms(500);
  95. //
  96. //        rgb_all_led(20,20,10);
  97. //        RGB_RAM = RGBpbuf3;
  98. //        RGB1W_SendRAM_Wait( rgb_data_bytes, RGB_RAM );
  99. //        Delay_Ms(500);

  100. //         t1+=5;
  101. //         t1%=70;
  102. //         rgb_all_led(t1,t1,t1);
  103. //         rgb_set_pixel(1,5,100,50);
  104. //
  105. //             RGB_RAM = RGBpbuf3;
  106. //             RGB1W_SendRAM_Wait( rgb_data_bytes, RGB_RAM );
  107. //
  108. //// long data
  109.         Delay_Ms(200);
  110.         stat = 0x80;//free
  111.         if ( stat != 0xFF ) {//RGB1W completed
  112.             if ( stat < 0x80 ) {//got status in interrupt
  113.                 if ( stat == RGB1W_ERR_OK ) printf("1-wire finished\r\n")/**/;
  114.                 else printf("1-wire error %02x\r\n", stat)/* */;
  115.                 stat = 0x80;//free
  116.             }
  117.             if ( stat == 0x80 && total_bytes && timer_to_run ) {//RAM mode for 1~3072 bytes data
  118.                 stat = 0xFF;//wait
  119.                 if(t1==0){
  120.                     t1 = 1;
  121.                     RGB_RAM = RGBpbuf;
  122.                 }
  123.                 else if(t1==1){
  124.                     t1 = 2;
  125.                     RGB_RAM = RGBpbuf1;
  126.                 }
  127.                 else if(t1==2){
  128.                     t1 = 0;
  129.                     RGB_RAM = RGBpbuf2;
  130.                 }
  131.                  RGB1W_SendRAM( total_bytes, RGB_RAM );

  132.                 total_bytes = 0;
  133.             }
  134.         }
  135.         if ( PIOC->D8_SYS_CFG & RB_INT_REQ ) {//query if disable interrupt
  136.             stat = PIOC->D8_CTRL_RD;//auto remove interrupt request after reading
  137.         }
  138.         }

  139. }



  140. void rgb_all_led(u8 color_r,u8 color_g,u8 color_b)
  141. {
  142.     u8 i;
  143.     for(i=0;i<RGB_LED_NUM;i++)
  144.     {
  145.         RGBpbuf3[3*i]     =color_r;
  146.         RGBpbuf3[3*i+1]   =color_g;
  147.         RGBpbuf3[3*i+2]   =color_b;
  148.     }

  149. }

  150. void rgb_set_pixel(u8 n,u8 color_r,u8 color_g,u8 color_b)
  151. {
  152.     RGBpbuf3[3*(n-1)]      =color_r;
  153.     RGBpbuf3[3*(n-1)+1]    =color_g;
  154.     RGBpbuf3[3*(n-1)+2]    =color_b;
  155. }


测试结果:
1、使用例程48M时钟,第一颗灯控制异常
2、使用24M时钟,LED数量较少时还能正常使用,数量增加后,大概是第11颗灯珠出现异常(48M也一样)
3、单步调试时观察内存数据,可以正常显示,但是全速运行时就会发生1、2的问题
4、怀疑过电平问题,硬件上增加缓冲驱动器依然无效
5、手册中没有关于PIOC的详细描述

评论

不错,赞一个  发表于 2023-10-30 21:50
chenjun89 发表于 2023-10-16 22:41 来自手机 | 显示全部楼层
可以直接控制2812灯珠的话,那就很方便了啊。
LIzs6 发表于 2023-10-17 14:23 | 显示全部楼层
关于第一颗灯控制异常问题,可参考下链接将PIOC_1W_CODE数组数据替换一下应该可以解决,你可以试一下。
https://www.cnblogs.com/wchmcu/p/17678765.html
 楼主| 90houyidai 发表于 2023-10-17 21:01 | 显示全部楼层
本帖最后由 90houyidai 于 2023-10-18 09:15 编辑
LIzs6 发表于 2023-10-17 14:23
关于第一颗灯控制异常问题,可参考下链接将PIOC_1W_CODE数组数据替换一下应该可以解决,你可以试一下。
htt ...

第一颗灯偶尔还会异常,第十八颗也是
您需要登录后才可以回帖 登录 | 注册

本版积分规则

36

主题

510

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部

36

主题

510

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部