Hallo.
Ich habe ein „crumbx128a1_v1.0“ Modul mit einem AtXmega128A1 und
versuche mit diesem seriell zu kommunizieren. Für die Kommunikation am
PC benutze ich das Programm „H-Term“. Leider funktioniert meine
Kommunikation nicht. Auf dem Modul ist noch ein USB-UART converter
(CP2102) und ich bin mir nicht sicher ob ich diesen zusätzlich noch
irgendwie initialisieren muss. Unten steht mein Quellcode. Vielleicht
kann mir jemand helfen.
Viele Grüße Robert.
PS: Allen noch ein gutes, neues Jahr.
1 | #include <avr/io.h>
|
2 | #include <iox128a1.h>
|
3 |
|
4 | unsigned char ch;
|
5 |
|
6 | void clock_init(void);
|
7 | void init_usart(void);
|
8 | void usart_rx_tx(void);
|
9 |
|
10 |
|
11 | int main(void)
|
12 | {
|
13 | clock_init();
|
14 |
|
15 | init_usart();
|
16 |
|
17 | while(1)
|
18 | {
|
19 | usart_rx_tx();
|
20 | }
|
21 | }
|
22 |
|
23 |
|
24 | void init_usart()
|
25 | {
|
26 | PORTF_DIR|=0x08; //set the direction of PC3 i.e. TXD0 as output and PC2 i.e. RXD0 as input
|
27 |
|
28 | USARTF0_BAUDCTRLA=0x19; //for baud rate 9600, BSEL=12, BSCALE=4 as per data sheet
|
29 |
|
30 | USARTF0_BAUDCTRLB=0x10; //BSCALE=4, upper 4 bits out of 12 bit used for USART baud rate setting will be zero
|
31 |
|
32 | USARTF0_CTRLB|=USART_RXEN_bm|USART_TXEN_bm; //enable USART receiver and transmitter
|
33 |
|
34 | USARTF0_CTRLC|=USART_CHSIZE1_bm|USART_CHSIZE0_bm; //asynchronous mode, 8-bit character size, 1 stop bit, no parity
|
35 | }
|
36 |
|
37 |
|
38 | void usart_rx_tx()
|
39 | {
|
40 | while(!(USARTC0_STATUS & USART_RXCIF_bm));
|
41 |
|
42 | ch=USARTC0_DATA; //receive character from user
|
43 |
|
44 | while(!(USARTC0_STATUS & USART_DREIF_bm));
|
45 |
|
46 | USARTC0_DATA=ch; //transmit the same character on terminal
|
47 | }
|
48 |
|
49 |
|
50 | void clock_init()
|
51 | {
|
52 | OSC_PLLCTRL=OSC_PLLFAC3_bm; //select internal 2MHz oscillator as PLL clock source, PLL multiplication factor as 8
|
53 |
|
54 | OSC_CTRL=OSC_PLLEN_bm; //enable PLL
|
55 |
|
56 | while(!(OSC_STATUS & OSC_PLLRDY_bm)); //wait until PLL is locked to desired frequency and ready to use
|
57 |
|
58 | CCP=0xd8; //write Configuration Change Protection register
|
59 |
|
60 | CLK_CTRL=CLK_SCLKSEL2_bm; //select PLL as system clock source
|
61 |
|
62 | CCP=0xd8; //write Configuration Change Protection register
|
63 |
|
64 | CLK_PSCTRL=CLK_PSADIV0_bm; //select Prescaler A as 2, Prescaler B and Prescaler C as 1, Clksys=16MHz, Clkper4=Clkper2=Clkper=Clkcpu=8MHz
|
65 |
|
66 | CLK_RTCCTRL=CLK_RTCEN_bm; //enable RTC clock source as 1KHz from 32KHz ULP internal oscillator
|
67 | }
|