liubiy

  • 2024-12-10
  • 加入了学习《【Follow me第二季第3期】所有任务汇总》,观看 【Follow me第二季第3期】所有任务汇总

  • 加入了学习《Follow me第二季第3期演示视频》,观看 Follow me第二季第3期演示视频

  • 上传了资料: 【Follow me第二季第3期】所有任务代码

  • 2024-12-04
  • 发表了主题帖: 【Follow me第二季第3期】所有任务汇总

    本帖最后由 liubiy 于 2024-12-10 13:53 编辑 一 、视频介绍     资料下载 https://download.eeworld.com.cn/detail/liubiy/635227 二、入门任务:搭建环境,下载调试示例程序,Blink,按键;       /* LED引脚置低电平 LED灯亮 */ #define LED1_ON R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_06, BSP_IO_LEVEL_HIGH) #define LED2_ON R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_07, BSP_IO_LEVEL_HIGH) #define LED3_ON R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_08, BSP_IO_LEVEL_HIGH) /* LED引脚置高电平 LED灯灭 */ #define LED1_OFF R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_06, BSP_IO_LEVEL_LOW) #define LED2_OFF R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_07, BSP_IO_LEVEL_LOW) #define LED3_OFF R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_08, BSP_IO_LEVEL_LOW) /* 使用寄存器来实现 LED灯翻转 */ #define LED1_TOGGLE R_PORT0->PODR ^= 1<<(BSP_IO_PORT_00_PIN_06 & 0xFF) #define LED2_TOGGLE R_PORT0->PODR ^= 1<<(BSP_IO_PORT_00_PIN_07 & 0xFF) #define LED3_TOGGLE R_PORT0->PODR ^= 1<<(BSP_IO_PORT_00_PIN_08 & 0xFF) /* 两个按键引脚定义 */ #define KEY1_SW2_PIN BSP_IO_PORT_00_PIN_04 #define KEY2_SW3_PIN BSP_IO_PORT_00_PIN_05 /* 按键扫描函数(阻塞式) * key: KEY1_SW2_PIN 用户按键1 * KEY2_SW3_PIN 用户按键2 */ uint32_t Key_Scan(bsp_io_port_pin_t key) { bsp_io_level_t state; // 读取按键引脚电平 R_IOPORT_PinRead(&g_ioport_ctrl, key, &state); if (BSP_IO_LEVEL_HIGH == state) { return KEY_OFF; //按键没有被按下 } else { do //等待按键释放 { R_IOPORT_PinRead(&g_ioport_ctrl, key, &state); } while (BSP_IO_LEVEL_LOW == state); } return KEY_ON; //按键被按下了 }   三、基础任务:quad-spi flash和octo-spi flash配置及读写速度测试;DAC配置生成波形及性能测试;    电脑通过USB连接开发板的USB接口,再e2 studio打开终端。再将示波器连接P014口。   1,quad-spi flash和octo-spi flash配置及读写速度测试:使用的是例程中的测试代码:   下载quickstart_ek_ra6m5_ep的代码,连接USB ,打开终端,选择flash速度对吧 运行结果: 运行的部分代码: sprintf(s_print_buffer, "\r\n\r\nGenerated a text block of %2lu KB in SRAM\r\n", block_size_actual); /* ignoring -Wpointer-sign is OK when treating signed char_t array as as unsigned */ print_to_console((void*)s_print_buffer); /* ignoring -Wpointer-sign is OK for a constant string */ print_to_console((uint8_t *) "\r\nWriting the text block to external Quad-SPI and Octo-SPI flash memories...\r\n"); uint32_t ospi_performance_write_result = 0; uint32_t ospi_performance_read_result = 0; uint32_t timer_frequency; R_GPT_InfoGet(g_memory_performance.p_ctrl, &timer_info); timer_frequency = timer_info.clock_frequency; ospi_performance_test (block_size_actual, &ospi_performance_write_result, &ospi_performance_read_result); /* Multiply uSec calcs by 100, to avoid losses due to small results in integer maths * Scaled to fit within uint32_t */ ospi_write_result = ((100000000 / timer_frequency) * ospi_performance_write_result) / 100; qspi_write_result = ((100000000 / timer_frequency) * qspi_write_test(block_size_actual)) / 100; /* ignoring -Wpointer-sign is OK for a constant string */ print_to_console((uint8_t *)"Writing to flash completed\r\n"); /* ignoring -Wpointer-sign is OK for a constant string */ print_to_console((uint8_t *)"\r\nReading the text block from external Quad-SPI and Octo-SPI flash memories...\r\n"); ospi_read_result = ((100000000 / timer_frequency) * ospi_performance_read_result) / 100; qspi_read_result = ((100000000 / timer_frequency) * qspi_read_test(block_size_actual)) / 100; /* ignoring -Wpointer-sign is OK for a constant string */ print_to_console((uint8_t *)"Reading from flash completed\r\n"); R_GPT_Close(g_memory_performance.p_ctrl); /* Handle error */ if (FSP_SUCCESS != fsp_err) { /* Fatal error */ SYSTEM_ERROR }   2,DAC配置生成波形及性能测试: 下载自己写的代码(01_Uart_Led_Key),连接P014发出的波形。   DAC的配置:   生成波形的代码: if(Key_Scan(KEY1_SW2_PIN)==KEY_ON){ frequency = frequency + 20; if(frequency >= 200){frequency = 50;}; } if(Key_Scan(KEY2_SW3_PIN)==KEY_ON){ mode++; if(mode == 4){mode = 0;} } Time = Time + 0.1f;if(Time > 200){Time = 0;} if(mode == 1){ DAC_Value = (uint16_t)(( sin(2 * M_PI * frequency * Time) + 1 ) / 2 * 4095); }else if(mode == 2){ DAC_Value = (uint16_t)( ( 2 / M_PI * asin(sin(2 * M_PI / frequency * Time)) + 1 ) * 4095 ); }else if(mode == 2){ Time1 = Time1 + 0.01f; if(Time1 > 200){Time1 = 0;} DAC_Value = (uint16_t)( (1-exp(-Time1/frequency)) * 4095 ); }else{ DAC_Value = (uint16_t)(2047); } R_DAC_Write(&g_dac0_ctrl, DAC_Value);   四、进阶任务:示例程序中新增命令打印信息; 实现一个:显示DAC频率和模式的参数:   修改的是例程中的测试代码: 添加一下显示界面的函数{"Task Information" , Task_display_menu} /* Table of menu functions */ static st_menu_fn_tbl_t s_menu_items[] = { {"Task Information" , Task_display_menu}, {"Kit Information" , kis_display_menu}, {"Web Server" , eth_emb_display_menu}, {"Network Name Lookup" , eth_www_display_menu}, {"Quad-SPI and Octo-SPI Speed Comparison" , ext_display_menu}, {"Cryptography and USB High speed (MSC)" , enc_display_menu}, {"Next Steps", ns_display_menu }, {"", NULL } }; 在menu_kis.c中添加 extern uint8_t frequency; extern uint8_t mode; #define TASK_NAME "\r\n%d. Signal Generator Task\r\n" #define SUB_TASK "\r\n\x1b[2m\x1b[37m a) Kit name: " \ "\r\n\x1b[2m\x1b[37m b) Kit ordering part number: " \ "\r\n\x1b[2m\x1b[37m c) RA Device part number: " \ "\r\n\x1b[2m\x1b[37m d) RA MCU 128-bit Unique ID (hex): " \ " " \ "\r\n\x1b[2m\x1b[37m e) RA MCU Die temperature (F/C): " \ "\r\n\x1b[2m\x1b[37m f) Blue LED blinking frequency (Hz): " \ "\r\n\x1b[2m\x1b[37m g) Blue LED blinking intensity (%%%%): " \ "\r\n\x1b[2m\x1b[37m h) Waveform mode (mode1:sine wave): \x1b[32m%d\x1b[37m " \ "\r\n\x1b[2m\x1b[37m l) Waveform frequency (Hz): \x1b[32m%d\x1b[37m " \ test_fn Task_display_menu(void) { int8_t c = -1; sprintf (s_print_buffer, "%s%s", gp_clear_screen, gp_cursor_home); print_to_console((void*)s_print_buffer); sprintf (s_print_buffer, TASK_NAME, g_selected_menu); print_to_console((void*)s_print_buffer); sprintf (s_print_buffer, SUB_TASK, mode, frequency); print_to_console((void*)s_print_buffer); sprintf (s_print_buffer, MENU_RETURN_INFO); print_to_console((void*)s_print_buffer); vTaskDelay (s_ticks_to_wait); xEventGroupSetBits (g_update_console_event, STATUS_DISPLAY_MENU_KIS); while (CONNECTION_ABORT_CRTL != c) { c = input_from_console (); if ((MENU_EXIT_CRTL == c) || (CONNECTION_ABORT_CRTL == c)) { break; } } xEventGroupClearBits (g_update_console_event, STATUS_DISPLAY_MENU_KIS); return (0); } 再添加头文件,就可以显示了     五、扩展任务:设计一个类似信号发生器功能的例程。   项目简介: 实现信号发生器功能,通过命令或按键,设置DAC输出波形,可通过flash存储历史波形等信息。 全部物料清单(含物料名称、实物图片):     用到了示波器,USB线,USB串口,开发板。   软件流程图:   关键代码: /* 按键和FALSH存储代码 */ if(Key_Scan(KEY1_SW2_PIN)==KEY_ON){ frequency = frequency + 20; if(frequency >= 200){frequency = 50;}; Write_Data[0] = frequency; err = erase_and_blankcheck(ospi_ref_addr); if(FSP_SUCCESS != err) { sprintf(test_str, "ERR erase_and_blankcheck: %d\n",err); R_SCI_UART_Write(&g_uart4_ctrl, (uint8_t const * const)test_str, strlen(test_str)); R_BSP_SoftwareDelay(10u, BSP_DELAY_UNITS_MILLISECONDS); } // Write Data err = R_OSPI_Write(&g_ospi_ctrl, Write_Data, ospi_ref_addr, (uint32_t)(OSPI_DATA_SIZE)); wait_operation(); if(FSP_SUCCESS != err) { sprintf(test_str, "** R_OSPI_Write API failed in SPI Operation **\r\n"); R_SCI_UART_Write(&g_uart4_ctrl, (uint8_t const * const)test_str, strlen(test_str)); R_BSP_SoftwareDelay(10u, BSP_DELAY_UNITS_MILLISECONDS); } sprintf(test_str, "** frequency_success:%d **\r\n",frequency); R_SCI_UART_Write(&g_uart4_ctrl, (uint8_t const * const)test_str, strlen(test_str)); R_BSP_SoftwareDelay(10u, BSP_DELAY_UNITS_MILLISECONDS); } if(Key_Scan(KEY2_SW3_PIN)==KEY_ON){ mode++; if(mode == 4){mode = 0;} Write_Data[1] = mode; err = erase_and_blankcheck(ospi_ref_addr); if(FSP_SUCCESS != err) { sprintf(test_str, "ERR erase_and_blankcheck: %d\n",err); R_SCI_UART_Write(&g_uart4_ctrl, (uint8_t const * const)test_str, strlen(test_str)); R_BSP_SoftwareDelay(10u, BSP_DELAY_UNITS_MILLISECONDS); } // Write Data err = R_OSPI_Write(&g_ospi_ctrl, Write_Data, ospi_ref_addr, (uint32_t)(OSPI_DATA_SIZE)); wait_operation(); if(FSP_SUCCESS != err) { sprintf(test_str, "** R_OSPI_Write API failed in SPI Operation **\r\n"); R_SCI_UART_Write(&g_uart4_ctrl, (uint8_t const * const)test_str, strlen(test_str)); R_BSP_SoftwareDelay(10u, BSP_DELAY_UNITS_MILLISECONDS); } sprintf(test_str, "** mode_success:%d **\r\n",mode); R_SCI_UART_Write(&g_uart4_ctrl, (uint8_t const * const)test_str, strlen(test_str)); R_BSP_SoftwareDelay(10u, BSP_DELAY_UNITS_MILLISECONDS); } 生成波形的代码: Time = Time + 1;if(Time > 20000){Time = 0;} if(mode == 1){ //sin() DAC_Value = (uint16_t)(( sin(2 * M_PI / frequency * Time) + 1 ) / 2 * 4095); }else if(mode == 2){ //3angle DAC_Value = (uint16_t)( ( 2 / M_PI * asin(sin(2 * M_PI / frequency * Time)) + 1 ) * 4095 ); }else if(mode == 2){ Time1 = Time1 + 1; if(Time1 > 20000){Time1 = 0;} DAC_Value = (uint16_t)( (1-exp(-Time1/frequency)) * 4095 ); }else{ DAC_Value = (uint16_t)(2047); } R_DAC_Write(&g_dac0_ctrl, DAC_Value);   六、心得体会 在制作DAC信号发生器的过程中,我深入了解了数字模拟转换器(DAC)的工作原理和在信号生成中的应用。通过设计和实现这个项目,我不仅提升了对嵌入式系统的理解,也对硬件和软件之间的协作有了更深刻的体会。在实际操作中,我学习了如何通过编程控制DAC输出不同频率和幅度的信号,掌握了与硬件通信、调试和优化程序的技巧。 项目中,我遇到了不少挑战,特别是在信号精度和稳定性方面。通过不断调整硬件设置和优化代码,我逐步解决了这些问题,成功实现了预定的功能。这不仅提高了我的动手能力,还让我对嵌入式系统中信号处理的细节有了更多的了解。总的来说,制作DAC信号发生器的过程让我收获颇丰,也让我更加坚定了未来继续深入嵌入式开发的决心。    

  • 2024-12-01
  • 加入了学习《FollowMe 第二季:3 - EK_RA6M5 开发板入门》,观看 EK-RA6M5 开发板入门

  • 2024-10-31
  • 发表了主题帖: 【Follow me第二季第3期】+遇见问题集

    本帖最后由 liubiy 于 2024-10-31 11:33 编辑 一,准备工作 1,安装编译环境     1.1,keil+RA_S..环境         下载代码时,keil jlink下载失败。      解决:     加入这些            如果有Cannot Load Flash Programming Algorithm的报错       把下载速度修改到最大。     1.2,  e2环境     没什么问题。 3,编程的资料     现在用到的:(在附件里)     3.1:开发板的原理图文件     3.2:开发板的资源介绍文件       

最近访客

< 1/1 >

统计信息

已有2人来访过

  • 芯积分:29
  • 好友:--
  • 主题:2
  • 回复:0

留言

你需要登录后才可以留言 登录 | 注册


现在还没有留言