大大通开发板评测专区
直播中

马猛

12年用户 293经验值
擅长:BLAC
私信 关注
[经验]

【大联大世平ON Semiconductor BLE5.0 RSL10开发板试用体验】BLE5.0 RSL10 ADC和USART测试。

`BLE5.0 RSL10有双核,其中同一个为ARM® Cortex®-M3 Processor 另一是 LPDSP32 DSP core 。

11.png ADC参数如下:
12.png
ADC 通道:An Analog to Digital converter (ADC), accessed by the Arm Cortex-M3 processor. The ADC can read 4 external values (DIO[0]-DIO[3]), AOUT, VDDC, VBAT/2 and the ADC offset value.
13.png

板子ADC 有串口发出:开发板符合Arduino所有接口标准定义。


端口示意图,CH340 USB转TTL3.3V
2.png

微信图片_20200725230857.jpg


用keil编程,调试。

4.png

Jlink独立下载:
3.png
结果如下,显示OK
1.png

程序如下:
  1. /* ----------------------------------------------------------------------------
  2. * Copyright (c) 2017 Semiconductor Components Industries, LLC (d/b/a
  3. * ON Semiconductor), All Rights Reserved
  4. *
  5. * This code is the property of ON Semiconductor and may not be redistributed
  6. * in any form without prior written permission from ON Semiconductor.
  7. * The terms of use and warranty for this code are covered by contractual
  8. * agreements between ON Semiconductor and the licensee.
  9. *
  10. * This is Reusable Code.
  11. *
  12. * ----------------------------------------------------------------------------
  13. * app.c
  14. * - ADC UART application that measure and monitor VBAT.
  15. * - The value of VBAT is sent by UART to a terminal.
  16. * - If the value of VBAT goes lower than 1.6 V a error message is sent.
  17. * - As battery monitor is only on Channel 6 or 7, the ADC_CHANNEL need to 6 or
  18. *   7.
  19. * ----------------------------------------------------------------------------
  20. * $Revision: 1.23 $
  21. * $Date: 2019/12/03 22:30:29 $
  22. * ------------------------------------------------------------------------- */

  23. #include
  24. #include
  25. #include

  26. /* ----------------------------------------------------------------------------
  27. * Global Variables Declaration
  28. * ------------------------------------------------------------------------- */
  29. volatile uint8_t data_ready_flag;
  30. volatile uint8_t bat_error_flag;
  31. volatile float adc_value;

  32. /* ----------------------------------------------------------------------------
  33. * Function      : void ADC_BATMON_IRQHandler(void)
  34. * ----------------------------------------------------------------------------
  35. * Description   : Handle ADC and BATMON interrupts. When the interrupt is from
  36. *                 ADC add the ADC value to the accumulator adc_value and
  37. *                 increment the counter. When counter reach 100 calculate the
  38. *                 average and set data_ready.
  39. *                 When the interrupt is from battery monitor set bat_error.
  40. * Inputs        : None
  41. * Outputs       : None
  42. * Assumptions   : None
  43. * ------------------------------------------------------------------------- */
  44. void ADC_BATMON_IRQHandler(void)
  45. {
  46.     static uint32_t adc_samples_count = 0;
  47.     static uint32_t adc_filter_sum    = 0.0f;

  48.     /* Get status of ADC */
  49.     uint32_t adc_status = Sys_ADC_Get_BATMONStatus();
  50.     if ((adc_status & (1 << ADC_BATMON_STATUS_BATMON_ALARM_STAT_Pos)) ==
  51.         BATMON_ALARM_TRUE)
  52.     {
  53.         /* Battery monitor alarm status is set */
  54.         bat_error_flag = 1;

  55.         /* Clear the battery monitor status and counter */
  56.         Sys_ADC_Clear_BATMONStatus();
  57.         uint32_t dummy = ADC->BATMON_COUNT_VAL;
  58.     }
  59.     else
  60.     {
  61.         adc_filter_sum = adc_filter_sum + ADC->DATA_TRIM_CH[ADC_CHANNEL];
  62.         adc_samples_count++;
  63.         if (adc_samples_count == ADC_FILTER_COUNTS)
  64.         {
  65.             adc_samples_count = 0;
  66.             adc_value = (adc_filter_sum + (float)ADC_FILTER_COUNTS / 2.0f) /
  67.                         (float)ADC_FILTER_COUNTS;
  68.             adc_filter_sum    = 0;
  69.             data_ready_flag   = 1;
  70.         }
  71.     }
  72. }

  73. /* ----------------------------------------------------------------------------
  74. * Function      : void Initialize(void)
  75. * ----------------------------------------------------------------------------
  76. * Description   : Initialize the system by disabling interrupts, switching to
  77. *                 the 8 MHz clock (divided from the 48 MHz crystal),
  78. *                 configuring the DIOs required for the UART interface,
  79. *                 configuring ADC to measure VBAT/2, enabling battery monitor
  80. *                 and enabling interrupts.
  81. * Inputs        : None
  82. * Outputs       : None
  83. * Assumptions   : None
  84. * ------------------------------------------------------------------------- */
  85. void Initialize(void)
  86. {
  87.     /* Mask all interrupts */
  88.     __set_PRIMASK(PRIMASK_DISABLE_INTERRUPTS);

  89.     /* Disable all existing interrupts, clearing all pending source */
  90.     Sys_NVIC_DisableAllInt();
  91.     Sys_NVIC_ClearAllPendingInt();

  92.     /* Test DIO12 to pause the program to make it easy to re-flash */
  93.     DIO->CFG[RECOVERY_DIO] = DIO_MODE_INPUT  | DIO_WEAK_PULL_UP |
  94.                              DIO_LPF_DISABLE | DIO_6X_DRIVE;
  95.     while (DIO_DATA->ALIAS[RECOVERY_DIO] == 0);

  96.     /* Prepare the 48 MHz crystal
  97.      * Start and configure VDDRF */
  98.     ACS_VDDRF_CTRL->ENABLE_ALIAS = VDDRF_ENABLE_BITBAND;
  99.     ACS_VDDRF_CTRL->CLAMP_ALIAS  = VDDRF_DISABLE_HIZ_BITBAND;

  100.     /* Wait until VDDRF supply has powered up */
  101.     while (ACS_VDDRF_CTRL->READY_ALIAS != VDDRF_READY_BITBAND);

  102.     /* Enable RF power switches */
  103.     SYSCTRL_RF_POWER_CFG->RF_POWER_ALIAS   = RF_POWER_ENABLE_BITBAND;

  104.     /* Remove RF isolation */
  105.     SYSCTRL_RF_ACCESS_CFG->RF_ACCESS_ALIAS = RF_ACCESS_ENABLE_BITBAND;

  106.     /* Start the 48 MHz oscillator without changing the other register bits */
  107.     RF->XTAL_CTRL = ((RF->XTAL_CTRL & ~XTAL_CTRL_DISABLE_OSCILLATOR) |
  108.                      XTAL_CTRL_REG_VALUE_SEL_INTERNAL);

  109.     /* Enable 48 MHz oscillator divider to generate an 8 MHz clock. */
  110.     RF_REG2F->CK_DIV_1_6_CK_DIV_1_6_BYTE = CK_DIV_1_6_PRESCALE_6_BYTE;

  111.     /* Wait until 48 MHz oscillator is started */
  112.     while (RF_REG39->ANALOG_INFO_CLK_DIG_READY_ALIAS !=
  113.            ANALOG_INFO_CLK_DIG_READY_BITBAND);

  114.     /* Switch to (divided 48 MHz) oscillator clock */
  115.     Sys_Clocks_SystemClkConfig(JTCK_PRESCALE_1 |
  116.                                EXTCLK_PRESCALE_1 |
  117.                                SYSCLK_CLKSRC_RFCLK);

  118.     /* Setup DIO6 as a GPIO output */
  119.     Sys_DIO_Config(LED_DIO, DIO_MODE_GPIO_OUT_0);

  120.     /* Initialize the UART and associated DMA */
  121.     UART_Initialize();

  122.     /* Set the ADC configuration */
  123.     Sys_ADC_Set_Config(ADC_VBAT_DIV2_NORMAL | ADC_NORMAL | ADC_PRESCALE_1280H);

  124.     /* Set the battery monitor interrupt configuration */
  125.     Sys_ADC_Set_BATMONIntConfig(INT_EBL_ADC |
  126.                                 ADC_CHANNEL <<
  127.                                 ADC_BATMON_INT_ENABLE_ADC_INT_CH_NUM_Pos |
  128.                                 INT_EBL_BATMON_ALARM);

  129.     /* Set the battery monitor configuration, use channel ADC_CHANNEL to battery
  130.      * monitoring. */
  131.     Sys_ADC_Set_BATMONConfig((100 << ADC_BATMON_CFG_ALARM_COUNT_VALUE_Pos) |
  132.                              (THRESHOLD_CFG <<
  133.                               ADC_BATMON_CFG_SUPPLY_THRESHOLD_Pos) |
  134.                              BATMON_CH(ADC_CHANNEL));

  135.     /* Configure ADC_CHANNEL input selection to VBAT/2 */
  136.     Sys_ADC_InputSelectConfig(ADC_CHANNEL, ADC_POS_INPUT_VBAT_DIV2 |
  137.                               ADC_NEG_INPUT_GND);

  138.     /* Configure both input selection for an ADC channel to GND so the OFFSET is
  139.      * subtracted automatically to result. */
  140.     Sys_ADC_InputSelectConfig(ADC_GND_CHANNEL, ADC_POS_INPUT_GND |
  141.                               ADC_NEG_INPUT_GND);

  142.     /* Enable interrupts */
  143.     NVIC_EnableIRQ(ADC_BATMON_IRQn);

  144.     /* Unmask all interrupts */
  145.     __set_PRIMASK(PRIMASK_ENABLE_INTERRUPTS);
  146. }

  147. /* ----------------------------------------------------------------------------
  148. * Function      : void Send_ADC_Value (void)
  149. * ----------------------------------------------------------------------------
  150. * Description   : Create a buffer with "ADC VALUE = x.xxx V" where x is the
  151. *                 ADC value read by the ADC and send it to the UART. The number
  152. *                 of digits of the mantissa is defined by NUM_DIGITS. The value
  153. *                 add to the buffer is truncated.
  154. * Inputs        : None
  155. * Outputs       : None
  156. * Assumptions   : None
  157. * ------------------------------------------------------------------------- */
  158. void Send_ADC_Value(void)
  159. {
  160.     uint8_t size;
  161.     float adc_in_volts;
  162.     char buffer[32];

  163.     /* Multiply by 2 as we measure VBAT/2 and divide by a gain factor to convert
  164.      * the value from ADC. */
  165.     adc_in_volts = (adc_value * 2.0f) / (float)ADC_GAIN;
  166.     sprintf(buffer, "ADC input value = %.3f V
  167. ", adc_in_volts);
  168.     size = strlen((const char *)buffer);
  169.     UART_FillTXBuffer(size, (uint8_t *)buffer);
  170.     PRINTF("ADC input value = %d mV
  171. ",(int32_t)(adc_in_volts * 1000));
  172. }

  173. /* ----------------------------------------------------------------------------
  174. * Function      : void Send_VBAT_Error (void)
  175. * ----------------------------------------------------------------------------
  176. * Description   : Create a buffer with "VBAT lower than threshold!!" and send
  177. *                 it to the UART.
  178. * Inputs        : None
  179. * Outputs       : None
  180. * Assumptions   : None
  181. * ------------------------------------------------------------------------- */
  182. void Send_VBAT_Error(void)
  183. {
  184.     uint8_t size;
  185.     const char buffer[] = "VBAT voltage lower than threshold!!
  186. ";
  187.     size = strlen(buffer);
  188.     UART_FillTXBuffer(size, (uint8_t *)buffer);
  189.     PRINTF("VBAT voltage lower than threshold!!
  190. ");
  191. }

  192. /* ----------------------------------------------------------------------------
  193. * Function      : int main(void)
  194. * ----------------------------------------------------------------------------
  195. * Description   : Initialize the system. The ADC value is read and an average
  196. *                 of 100 values are made. When the average value is calculated
  197. *                 it's sent by UART. If a battery monitor interrupt is
  198. *                 generated an error message is sent by UART.
  199. * Inputs        : None
  200. * Outputs       : None
  201. * Assumptions   : None
  202. * ------------------------------------------------------------------------- */
  203. int main(void)
  204. {
  205.     /* Initialize global variables */
  206.     data_ready_flag = 0;
  207.     bat_error_flag  = 0;
  208.     adc_value = 0.0f;

  209.     /* Initialize the system */
  210.     Initialize();
  211.     PRINTF("DEVICE INITIALIZED
  212. ");
  213.     /* Spin loop */
  214.     while (1)
  215.     {
  216.         /* Refresh the watch-dog timer */
  217.         Sys_Watchdog_Refresh();

  218.         if (data_ready_flag == 1)
  219.         {
  220.             data_ready_flag = 0;
  221.             Send_ADC_Value();
  222.         }
  223.         if (bat_error_flag == 1)
  224.         {
  225.             bat_error_flag = 0;
  226.             Send_VBAT_Error();
  227.         }
  228.     }
  229. }










` 微信图片_20200725230839.jpg

更多回帖

发帖
×
20
完善资料,
赚取积分