example now echos back UART communication
This commit is contained in:
parent
f0d2933ff8
commit
55cb2009d9
|
@ -13,9 +13,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/* Copyright (c) 2016 King Kévin <kingkevin@cuvoodoo.info> */
|
/* Copyright (c) 2016 King Kévin <kingkevin@cuvoodoo.info> */
|
||||||
/* this library handles the USART
|
/* this library handles the USART */
|
||||||
* it uses the TX and RX pins (depending on which USART is used)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* standard libraries */
|
/* standard libraries */
|
||||||
#include <stdint.h> // standard integer types
|
#include <stdint.h> // standard integer types
|
||||||
|
@ -55,7 +53,8 @@ void usart_setup(void)
|
||||||
usart_set_parity(USART, USART_PARITY_NONE);
|
usart_set_parity(USART, USART_PARITY_NONE);
|
||||||
usart_set_flow_control(USART, USART_FLOWCONTROL_NONE);
|
usart_set_flow_control(USART, USART_FLOWCONTROL_NONE);
|
||||||
|
|
||||||
nvic_enable_irq(USART_IRQ); // enable the USART2 interrupt
|
nvic_enable_irq(USART_IRQ); // enable the USART interrupt
|
||||||
|
usart_enable_rx_interrupt(USART); // enable receive interrupt
|
||||||
usart_enable(USART); // enable USART
|
usart_enable(USART); // enable USART
|
||||||
|
|
||||||
/* reset buffer states */
|
/* reset buffer states */
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/* Copyright (c) 2016 King Kévin <kingkevin@cuvoodoo.info> */
|
/* Copyright (c) 2016 King Kévin <kingkevin@cuvoodoo.info> */
|
||||||
/* This library handles the USART */
|
/* this library handles the USART */
|
||||||
|
|
||||||
/* which USART to use */
|
/* which USART to use */
|
||||||
#define USART USART1
|
#define USART USART1
|
||||||
|
|
20
main.c
20
main.c
|
@ -61,24 +61,22 @@ static void gpio_setup(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int i, c = 0;
|
|
||||||
|
|
||||||
SCB_VTOR = (uint32_t) 0x08002000; // relocate vector table because of the bootloader
|
SCB_VTOR = (uint32_t) 0x08002000; // relocate vector table because of the bootloader
|
||||||
|
|
||||||
clock_setup();
|
clock_setup(); // setup main clock
|
||||||
gpio_setup();
|
gpio_setup(); // setup main inputs/ouputs
|
||||||
usart_setup();
|
usart_setup(); // setup USART (for printing)
|
||||||
setbuf(stdout, NULL); // set standard out buffer to NULL to immediately print
|
setbuf(stdout, NULL); // set standard out buffer to NULL to immediately print
|
||||||
setbuf(stderr, NULL); // set standard error buffer to NULL to immediately print
|
setbuf(stderr, NULL); // set standard error buffer to NULL to immediately print
|
||||||
|
|
||||||
/* blink the LED with every transmitted character */
|
/* blink the LED with every transmitted character */
|
||||||
while (1) {
|
while (1) {
|
||||||
gpio_toggle(LED_PORT, LED_PIN); /* LED on/off */
|
while (usart_received) { // echo every received character
|
||||||
printf("%c",c+'0');
|
gpio_toggle(LED_PORT, LED_PIN); // toggle LED
|
||||||
c = (c == 9) ? 0 : c + 1; /* increment c */
|
printf("%c",usart_getchar()); // transmit receive character
|
||||||
for (i = 0; i < 8000000; i++) /* wait a bit */
|
}
|
||||||
__asm__("nop");
|
__asm__("wfi"); // go to sleep
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue