昨晚捣鼓了一下串口。
代码:
#include <string.h>
#include "main.h"
#include "md_gpio.h"
#include "md_usart.h"
/** @addtogroup Projects_Examples_MD
* @{
*/
/** @addtogroup Examples
* @{
*/
md_usart_init_t init;
uint8_t tx_buf[32];
uint8_t rx_buf[32];
uint16_t k;
/**
* @brief Initializate pin
* @retval None
*/
void usart_pin_init(void)
{
md_gpio_init_t x;
/* Initialize tx pin */
x.mode = GPIO_MODE_OUTPUT;
x.odos = GPIO_PUSH_PULL;
x.pupd = GPIO_PUSH_UP;
x.odrv = GPIO_OUT_DRIVE_NORMAL;
x.flt = GPIO_FILTER_DISABLE;
x.type = GPIO_TYPE_TTL;
x.func = GPIO_FUNC_3;
md_gpio_init(USART0_TX_PORT, USART0_TX_PIN, &x);
/* Initialize rx pin */
x.mode = GPIO_MODE_INPUT;
x.odos = GPIO_PUSH_PULL;
x.pupd = GPIO_PUSH_UP;
x.odrv = GPIO_OUT_DRIVE_NORMAL;
x.flt = GPIO_FILTER_DISABLE;
x.type = GPIO_TYPE_TTL;
x.func = GPIO_FUNC_3;
md_gpio_init(USART0_RX_PORT, USART0_RX_PIN, &x);
return;
}
/**
* @brief Test main function
* @retval Status.
*/
int main()
{
/* Initialize 1ms tick */
md_init_1ms_tick();
/* clear md_usart_init_t structure */
memset(&init, 0x0, sizeof(md_usart_init_t));
/* Initialize pin */
usart_pin_init();
/* Initialize tx_buf */
memset(tx_buf, 0x55, 32);
/* Initialize USART */
init.baud = 115200;
init.word_length = MD_USART_WORD_LENGTH_8B;
init.stop_bits = MD_USART_STOP_BITS_1;
init.parity = MD_USART_PARITY_NONE;
init.fctl = MD_USART_HW_FLOW_CTL_NONE;
init.mode = MD_USART_MODE_TX_RX;
md_usart_init(USART0, &init);
while (1)
{
/* Send a message */
md_usart_send_data8(USART0, 0x66);
for(k=0;k<20000;k++);
}
}
效果图:
|