wenyangzeng 发表于 2022-3-10 20:28

(5)基于GD32L233C-START的低功耗远程数据监控系统

本帖最后由 wenyangzeng 于 2022-3-12 16:50 编辑

<p>【GD32L233C-START 评测】(5)基于GD32L233C-START的低功耗远程数据监控系统</p>

<p>&nbsp;</p>

<p>&nbsp; &nbsp; &nbsp; 本次评测是《评测2-4》的综合,集片内资源LPUART、LPTIMER、硬件过采样ADC、低功耗而成的低功耗远程数据监控系统。体验了GD32L233C独特的低功耗特性。使用了拓普微HMT070E TD-1D智能模块作为终端,而GD32L233C-START通过LPUART与HMT070E TD-1D智能模块进行远程通讯。</p>

<p>&nbsp;</p>

<p><br />
&nbsp; &nbsp; &nbsp;GD32L233C工作于deepsleep深度睡眠模式,低功耗定时器LPTIMER大约每2秒左右中断一次,唤醒CPU。唤醒后启动一次硬件过采样ADC,读取芯片内部温度传感器的温度值,计算成具有2位小数的浮点小数,通过低功耗串口LPUART发送至HMT070E TD-1D智能模块,在LCD屏上显示温度值。接着再次进入deepsleep睡眠模式。LED1在CPU唤醒后点亮,进入睡眠模式后熄灭。<br />
&nbsp; &nbsp; LPUART发送一次温度数据的命令格式是:<br />
0xaa,0x44,0x00,0x02,0x00,0x00,0x41,0xa7,0x04,0x14,0xcc,0x33,0xc3,0x3c<br />
其中字节6到字节9是浮点小数数据。</p>

<p>&nbsp; &nbsp; &nbsp;本次评测达到预期效果。由于GD32L233C-START 没有预留IDD接口,无法测量整机耗电,本想割断PCB铜箔引出,但担心万一失败就会中断评测工作,故未实施。希望日后有所改进。</p>

<p>&nbsp; &nbsp; 感谢EEWORLD, 感谢兆易创新提供给我一次难得锻炼机会和平台。使我在这次评测过程深刻体会了GD32L233C这款Cortex-M23低功耗芯片的许多优异性能。</p>

<p>&nbsp;</p>

<p>代码</p>

<pre>
<code>#include &quot;gd32l23x.h&quot;
#include &quot;systick.h&quot;
#include &lt;stdio.h&gt;
#include &quot;gd32l233r_eval.h&quot;
#include &quot;math.h&quot;
#include &lt;stdio.h&gt;
#include &quot;stdlib.h&quot;

#define ADC_TEMP_CALIBRATION_VALUE          REG16(0x1FFFF7F8)
#define LPUART_RDATA_ADDRESS      ((uint32_t)&amp;LPUART_RDATA)

uint16_t adc_value = 0U;
float temperature;
int32_t value;
uint8_t rxbuffer;
uint8_t Tx_Buffer={0xaa,0x44,0x00,0x02,0x00,0x00,0x41,0xa7,0x04,0x14,0xcc,0x33,0xc3,0x3c};
uint8_t tx_count = 0;
__IO uint8_t rx_count = 0;
__IO uint8_t receive_flag = 0;
__IO uint8_t ADC_EN=0;

void gpio_config(void);
void rcu_config(void);
void adc_config(void);
void lpuart_config(void);
void lptimer_config(void);
void nvic_config(void);
void Get_ADC(void);
int f_bin(float dat);

int main(void)
{uint8_t i;
   systick_config();
   gd_eval_led_init(LED1);
   gd_eval_key_init(KEY_WAKEUP, KEY_MODE_GPIO);
    rcu_config();       
   gpio_config();
    adc_config();
        for(i=0;i&lt;3;i++)
        {
        adc_software_trigger_enable(ADC_INSERTED_CHANNEL);
        value = (int32_t)ADC_TEMP_CALIBRATION_VALUE;
        }
        lpuart_config();
        lptimer_config();
        nvic_config();
   while(1) {
               gd_eval_led_off(LED1);
               pmu_to_deepsleepmode(PMU_LDNPDSP_LOWDRIVE, WFI_CMD, PMU_DEEPSLEEP);
               Get_ADC();
    }
}

void rcu_config(void)
{
   rcu_periph_clock_enable(RCU_PMU);
   rcu_periph_clock_enable(RCU_GPIOA);
   rcu_periph_clock_enable(RCU_GPIOC);
   rcu_periph_clock_enable(RCU_ADC);
   rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);
rcu_osci_on(RCU_IRC32K);
   rcu_osci_stab_wait(RCU_IRC32K);
   rcu_lptimer_clock_config(RCU_LPTIMERSRC_IRC32K);
   rcu_periph_clock_enable(RCU_LPTIMER);
}

void gpio_config(void)
{
    gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_4);
    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_4);
    gpio_af_set(GPIOA, GPIO_AF_2, GPIO_PIN_4);
}

void adc_config(void)
{
    adc_channel_length_config(ADC_INSERTED_CHANNEL, 1);
    adc_inserted_channel_config(0U, ADC_CHANNEL_16, ADC_SAMPLETIME_239POINT5);
    adc_external_trigger_source_config(ADC_INSERTED_CHANNEL, ADC_EXTTRIG_INSERTED_NONE);
    adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
    adc_special_function_config(ADC_SCAN_MODE, DISABLE);
    adc_channel_16_to_19(ADC_TEMP_CHANNEL_SWITCH, ENABLE);
    adc_external_trigger_config(ADC_INSERTED_CHANNEL, ENABLE);
    adc_oversample_mode_config(ADC_OVERSAMPLING_ALL_CONVERT, ADC_OVERSAMPLING_SHIFT_8B, ADC_OVERSAMPLING_RATIO_MUL256);
    adc_oversample_mode_enable();
    adc_enable();
    delay_1ms(1U);
    adc_calibration_enable();
}

void lpuart_config(void)
{
    rcu_periph_clock_enable(RCU_GPIOA);
    rcu_periph_clock_enable(RCU_LPUART);
    gpio_af_set(GPIOA, GPIO_AF_8, GPIO_PIN_2);
    gpio_af_set(GPIOA, GPIO_AF_8, GPIO_PIN_3);
    gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_2);
    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_2);
    gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_3);
    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_3);

    lpuart_deinit();
    lpuart_word_length_set(LPUART_WL_8BIT);
    lpuart_stop_bit_set(LPUART_STB_1BIT);
    lpuart_parity_config(LPUART_PM_NONE);
    lpuart_baudrate_set(115200U);
    lpuart_receive_config(LPUART_RECEIVE_ENABLE);
    lpuart_transmit_config(LPUART_TRANSMIT_ENABLE);
    lpuart_enable();
}

void nvic_config(void)
{
   nvic_irq_enable(LPTIMER_IRQn, 1U);
   exti_init(EXTI_29, EXTI_INTERRUPT, EXTI_TRIG_RISING);
    exti_interrupt_flag_clear(EXTI_29);
}

void lptimer_config(void)
{
    lptimer_parameter_struct lptimer_structure;
    lptimer_deinit();
    lptimer_struct_para_init(&amp;lptimer_structure);
    lptimer_structure.clocksource      = LPTIMER_INTERNALCLK;
    lptimer_structure.prescaler      = LPTIMER_PSC_16;
    lptimer_structure.extclockpolarity = LPTIMER_EXTERNALCLK_RISING;
    lptimer_structure.extclockfilter   = LPTIMER_EXTERNALCLK_FILTEROFF;
    lptimer_structure.triggermode      = LPTIMER_TRIGGER_SOFTWARE;
    lptimer_structure.extriggersource= LPTIMER_EXTRIGGER_GPIO;
    lptimer_structure.extriggerfilter= LPTIMER_TRIGGER_FILTEROFF;
    lptimer_structure.outputpolarity   = LPTIMER_OUTPUT_NOTINVERTED;
    lptimer_structure.outputmode       = LPTIMER_OUTPUT_PWMORSINGLE;
    lptimer_structure.countersource    = LPTIMER_COUNTER_INTERNAL;
    lptimer_init(&amp;lptimer_structure);
    lptimer_register_shadow_disable();
    lptimer_timeout_disable();
    lptimer_inputremap(LPTIMER_INPUT0_GPIO, LPTIMER_INPUT1_GPIO);
    lptimer_interrupt_flag_clear(LPTIMER_INT_FLAG_CMPVM | LPTIMER_INT_FLAG_CARM);
    lptimer_interrupt_enable(LPTIMER_INT_CMPVM | LPTIMER_INT_CARM);
    lptimer_countinue_start(9999U, 5000U);
    while(lptimer_counter_read() == 0) {
    }
}
void Get_ADC(void)
{ uint8_t i;
        gd_eval_led_on(LED1);
        delay_1ms(1);
        adc_software_trigger_enable(ADC_INSERTED_CHANNEL);
        value = (int32_t)ADC_TEMP_CALIBRATION_VALUE;
        temperature = ((float)((int32_t)ADC_IDATA0-value ) * 3.3f / 4095 * 1000 / 4.3f) + 25;

        f_bin(temperature);
        for (i=0;i&lt;14;i++)
                {
                lpuart_data_transmit((uint8_t)Tx_Buffer<i>);
                        while(RESET == lpuart_flag_get(LPUART_FLAG_TBE));
                }
                delay_1ms(5);               
}

void LPTIMER_IRQHandler()
{
    if(RESET != exti_interrupt_flag_get(EXTI_29)) {
      exti_interrupt_flag_clear(EXTI_29);
                        ADC_EN=1;
    }
    if(RESET != lptimer_interrupt_flag_get(LPTIMER_INT_FLAG_CMPVM)) {
      lptimer_interrupt_flag_clear(LPTIMER_INT_FLAG_CMPVM);
      ADC_EN=1;
                        SystemInit();
    }
               
    if(RESET != lptimer_interrupt_flag_get(LPTIMER_INT_FLAG_CARM)) {
      lptimer_interrupt_flag_clear(LPTIMER_INT_FLAG_CARM);
                       ADC_EN=1;
       SystemInit();
    }
}</i></code></pre>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><i>视频</i></p>

<p><i>南方的春天气候宜人。</i></p>

<p>&nbsp;</p>

<p><i><iframe allowfullscreen="true" frameborder="0" height="450" src="http://player.youku.com/embed/XNTg0OTU2OTA2NA" style="background:#eee;margin-bottom:10px;" width="700"></iframe><br />
&nbsp;</i></p>

<p><i>HEX文件</i></p>

<p></p>

<p><span style="color:#e74c3c;">HEX文件谨慎写入片中,以免因CPU深度睡眠下再次写入遇到困难!</span></p>

慈俭不敢为人先 发表于 2022-3-23 14:22

<p>期待后续更新</p>
页: [1]
查看完整版本: (5)基于GD32L233C-START的低功耗远程数据监控系统