summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/lm32/milkymist/Documentation/uart.txt
blob: b5b93043e90855a0c0f3ce7700059d7e05ebf318 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Initialization : 

	set the CSR_UART_DIVISOR to the correct VALUE,
	depending on the internal frequency of the LatticeMico32 softcore.

	for the ML401 board, this value is calculated using this formula : clk_frequency/230400/16
	clk_frequency  = 100000000 Hz
	=> we must set CSR_UART_DIVISOR to 27

How to send a byte to uart : 

void writechar(char c)
{
	        CSR_UART_RXTX = c;
		while(!(irq_pending() & IRQ_UARTTX));
		irq_ack(IRQ_UARTTX);
}

How to receive a byte from uart : 


char readchar()
{
	char c;
	while(!(irq_pending() & IRQ_UARTRX));
	irq_ack(IRQ_UARTRX);
	c = CSR_UART_RXTX;
	return c;
}