generated from hulk/gd32e23x_template
81 lines
2.0 KiB
C
81 lines
2.0 KiB
C
/*!
|
|
\file main.c
|
|
\brief led spark with systick, USART print and key example
|
|
|
|
\version 2024-02-22, V2.1.0, firmware for GD32E23x
|
|
*/
|
|
#include "main.h"
|
|
#include <stdio.h>
|
|
#include "gd32e23x.h"
|
|
#include "systick.h"
|
|
#include "gd32e23x_libopt.h"
|
|
#include "RS485.h"
|
|
#include "LDC1612.h"
|
|
|
|
uint32_t g_temperature_uint32;
|
|
|
|
void led_config(void) {
|
|
rcu_periph_clock_enable(LED_RCU);
|
|
|
|
gpio_mode_set(LED_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_PIN);
|
|
gpio_output_options_set(LED_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LED_PIN);
|
|
gpio_bit_write(LED_PORT, LED_PIN, SET);
|
|
|
|
rcu_periph_clock_enable(LED_TIMER_RCU);
|
|
timer_deinit(LED_TIMER);
|
|
|
|
timer_parameter_struct timer_initpara;
|
|
timer_struct_para_init(&timer_initpara);
|
|
timer_initpara.prescaler = 799;
|
|
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
|
|
timer_initpara.counterdirection = TIMER_COUNTER_UP;
|
|
timer_initpara.period = 999;
|
|
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
|
|
timer_init(LED_TIMER, &timer_initpara);
|
|
|
|
timer_auto_reload_shadow_enable(LED_TIMER);
|
|
timer_interrupt_enable(LED_TIMER, TIMER_INT_UP);
|
|
|
|
timer_enable(LED_TIMER);
|
|
|
|
nvic_irq_enable(LED_IRQ, 2);
|
|
}
|
|
|
|
/*!
|
|
\brief main function
|
|
\param[in] none
|
|
\param[out] none
|
|
\retval none
|
|
*/
|
|
int main(void) {
|
|
/* configure systick */
|
|
systick_config();
|
|
RS485_config();
|
|
led_config();
|
|
i2c_gpio_config();
|
|
i2c_config();
|
|
|
|
uint32_t raw_value = 0;
|
|
|
|
delay_ms(500);
|
|
ldc1612_iic_get_sensor_infomation();
|
|
|
|
ldc1612_single_ch0_config();
|
|
|
|
while (1) {
|
|
delay_ms(500);
|
|
raw_value = ldc1612_get_raw_channel_result(CHANNEL_0);
|
|
printf("data:%ld\r\n",raw_value);
|
|
g_temperature_uint32 = TMP112A_ReadTemperature();
|
|
}
|
|
}
|
|
|
|
/* retarget the C library printf function to the USART */
|
|
int _write(int fd, char *pBuffer, int size) {
|
|
for (int i = 0; i < size; i++) {
|
|
usart_data_transmit(USART0, (uint8_t) pBuffer[i]);
|
|
while (RESET == usart_flag_get(USART0, USART_FLAG_TBE));
|
|
}
|
|
return size;
|
|
}
|