blob: 4abaf6bdaf2db4006558e7db42b22686fc1e4750 [file] [log] [blame]
Christina Quast6219b5c2014-12-02 13:09:49 +01001#include "board.h"
2#include "spi.h"
3#include "pio.h"
4#include "pmc.h"
5#include "usart.h"
6
7#define BUFFER_SIZE 20
8
9/** Pins to configure for the application.*/
10const Pin pins[] = { BOARD_PIN_USART_RXD,
11 BOARD_PIN_USART_TXD
12// PIN_USART1_SCK,
13// BOARD_PIN_USART_RTS,
14// BOARD_PIN_USART_CTS,
15// PINS_SPI,
16// PIN_SPI_NPCS0_PA11
17 };
18
19char Buffer[BUFFER_SIZE] = "Hello World";
20/**
21 * \brief Configures USART in synchronous mode,8N1
22 * * \param mode 1 for master, 0 for slave
23 * */
24static void _ConfigureUsart(uint32_t freq )
25{
26 uint32_t mode;
27/* MASTER; mode = US_MR_USART_MODE_NORMAL
28 | US_MR_USCLKS_MCK
29 | US_MR_CHMODE_NORMAL
30 | US_MR_CLKO
31 | US_MR_SYNC // FIXME: sync or not sync?
32 | US_MR_MSBF
33 | US_MR_CHRL_8_BIT
34 | US_MR_NBSTOP_1_BIT
35 | US_MR_PAR_NO ;
36*/
37
38
39// Slave mode:
40 mode = US_MR_USART_MODE_NORMAL
41// | US_MR_USCLKS_SCK // we don't have serial clock, do we?
42 | US_MR_CHMODE_NORMAL
43// | US_MR_SYNC
44 | US_MR_MSBF
45 | US_MR_CHRL_8_BIT
46 | US_MR_NBSTOP_1_BIT
47 | US_MR_PAR_NO;
48
49 /* Enable the peripheral clock in the PMC */
50 PMC_EnablePeripheral( BOARD_ID_USART ) ;
51
52 /* Configure the USART in the desired mode @USART_SPI_CLK bauds*/
53 USART_Configure( BOARD_USART_BASE, mode, freq, BOARD_MCK ) ;
54
55 /* enable USART1 interrupt */
56// NVIC_EnableIRQ( USART1_IRQn ) ;
57
58 /* Enable receiver & transmitter */
59 USART_SetTransmitterEnabled( BOARD_USART_BASE, 1 ) ;
60 USART_SetReceiverEnabled( BOARD_USART_BASE, 1 ) ;
61}
62
63int main() {
64 /* Configure pins */
65 PIO_Configure( pins, PIO_LISTSIZE( pins ) ) ;
66
67 _ConfigureUsart( 1000000UL);
68
69 USART_WriteBuffer(BOARD_USART_BASE, Buffer, BUFFER_SIZE);
70
71// FIXME: do we need to call USARTEnable?
72
73
74// FIXME: do we need to call USARTDisable?
75
76 return 0;
77}