Rev 1576 | Rev 1695 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1576 | Rev 1578 | ||
|---|---|---|---|
| Line 176... | Line 176... | ||
| 176 | static uint8_t parityOdd = 0; |
176 | static uint8_t parityOdd = 0; |
| 177 | static uint8_t twoStopBits = 0; |
177 | static uint8_t twoStopBits = 0; |
| 178 | static uint8_t charSize = 8; |
178 | static uint8_t charSize = 8; |
| 179 | 179 | ||
| 180 | 180 | ||
| 181 | static void uart_updateConfig() |
181 | static void uart_updateConfig(void) |
| 182 | { |
182 | { |
| 183 | uint8_t CHARSIZE_MASK = 0; |
183 | uint8_t CHARSIZE_MASK = 0; |
| 184 | if (charSize |
184 | if (charSize==5) { |
| 185 | CHARSIZE_MASK = (0<< |
185 | CHARSIZE_MASK = (0<<UCSZ02) | (0<<UCSZ01) | (0<<UCSZ00); |
| 186 | } |
186 | } |
| 187 | else if (charSize |
187 | else if (charSize==6) { |
| 188 | CHARSIZE_MASK = (0<< |
188 | CHARSIZE_MASK = (0<<UCSZ02) | (0<<UCSZ01) | (1<<UCSZ00); |
| 189 | } |
189 | } |
| 190 | else if (charSize |
190 | else if (charSize==7) { |
| 191 | CHARSIZE_MASK = (0<< |
191 | CHARSIZE_MASK = (0<<UCSZ02) | (1<<UCSZ01) | (0<<UCSZ00); |
| 192 | } |
192 | } |
| 193 | else if (charSize |
193 | else if (charSize==8) { |
| 194 | CHARSIZE_MASK = (0<< |
194 | CHARSIZE_MASK = (0<<UCSZ02) | (1<<UCSZ01) | (1<<UCSZ00); |
| 195 | } |
195 | } |
| 196 | else if (charSize |
196 | else if (charSize==9) { |
| 197 | CHARSIZE_MASK = (1<< |
197 | CHARSIZE_MASK = (1<<UCSZ02) | (1<<UCSZ01) | (1<<UCSZ00); |
| 198 | } |
198 | } |
| 199 |
|
199 | UCSR0C = (parityEnabled<<UPM00) | (parityOdd<<UPM01) | (twoStopBits<<USBS0) | CHARSIZE_MASK; |
| 200 | } |
200 | } |
| 201 | 201 | ||
| 202 | 202 | ||
| 203 | void uart_setParity(uint8_t enabled, uint8_t odd) |
203 | void uart_setParity(uint8_t enabled, uint8_t odd) |
| 204 | { |
204 | { |
| Line 340... | Line 340... | ||
| 340 | UBRR0L = (unsigned char) baudrate; |
340 | UBRR0L = (unsigned char) baudrate; |
| 341 | 341 | ||
| 342 | /* Enable USART receiver and transmitter and receive complete interrupt */ |
342 | /* Enable USART receiver and transmitter and receive complete interrupt */ |
| 343 | UART0_CONTROL = _BV(RXCIE0)|(1<<RXEN0)|(1<<TXEN0); |
343 | UART0_CONTROL = _BV(RXCIE0)|(1<<RXEN0)|(1<<TXEN0); |
| 344 | 344 | ||
| 345 | /* Set frame format: asynchronous, 8data, no parity, 1stop bit */ |
- | |
| 346 |
|
345 | /* Set frame format */ |
| 347 | UCSR0C = (1<<URSEL0)|(3<<UCSZ00); |
- | |
| 348 | #else |
- | |
| 349 |
|
346 | uart_updateConfig(); |
| 350 | #endif |
- | |
| 351 | 347 | ||
| 352 | #elif defined ( ATMEGA_UART ) |
348 | #elif defined ( ATMEGA_UART ) |
| 353 | /* set baud rate */ |
349 | /* set baud rate */ |
| 354 | if ( baudrate & 0x8000 ) |
350 | if ( baudrate & 0x8000 ) |
| 355 | { |
351 | { |
| Line 392... | Line 388... | ||
| 392 | 388 | ||
| 393 | return (UART_LastRxError << 8) + data; |
389 | return (UART_LastRxError << 8) + data; |
| 394 | 390 | ||
| 395 | }/* uart_getc */ |
391 | }/* uart_getc */ |
| 396 | 392 | ||
| 397 | 393 | ||
| 398 | /************************************************************************* |
394 | /************************************************************************* |
| 399 | Function: uart_putc() |
395 | Function: uart_putc() |
| 400 | Purpose: write byte to ringbuffer for transmitting via UART |
396 | Purpose: write byte to ringbuffer for transmitting via UART |
| 401 | Input: byte to be transmitted |
397 | Input: byte to be transmitted |
| 402 | Returns: none |
398 | Returns: none |
| Line 440... | Line 436... | ||
| 440 | Purpose: transmit string from program memory to UART |
436 | Purpose: transmit string from program memory to UART |
| 441 | Input: program memory string to be transmitted |
437 | Input: program memory string to be transmitted |
| 442 | Returns: none |
438 | Returns: none |
| 443 | **************************************************************************/ |
439 | **************************************************************************/ |
| 444 | void uart_puts_p(const char *progmem_s ) |
440 | void uart_puts_p(const char *progmem_s ) |
| 445 | { |
441 | { |
| 446 | register char c; |
442 | register char c; |
| 447 | 443 | ||
| 448 | while ( (c = pgm_read_byte(progmem_s++)) ) |
444 | while ( (c = pgm_read_byte(progmem_s++)) ) |
| 449 | uart_putc(c); |
445 | uart_putc(c); |
| 450 | 446 | ||
| Line 465... | Line 461... | ||
| 465 | unsigned char tmphead; |
461 | unsigned char tmphead; |
| 466 | unsigned char data; |
462 | unsigned char data; |
| 467 | unsigned char usr; |
463 | unsigned char usr; |
| 468 | unsigned char lastRxError; |
464 | unsigned char lastRxError; |
| 469 | 465 | ||
| 470 | 466 | ||
| 471 | /* read UART status register and UART data register */ |
467 | /* read UART status register and UART data register */ |
| 472 | usr = UART1_STATUS; |
468 | usr = UART1_STATUS; |
| 473 | data = UART1_DATA; |
469 | data = UART1_DATA; |
| 474 | 470 | ||
| 475 | /* */ |
471 | /* */ |
| Line 537... | Line 533... | ||
| 537 | UBRR1L = (unsigned char) baudrate; |
533 | UBRR1L = (unsigned char) baudrate; |
| 538 | 534 | ||
| 539 | /* Enable USART receiver and transmitter and receive complete interrupt */ |
535 | /* Enable USART receiver and transmitter and receive complete interrupt */ |
| 540 | UART1_CONTROL = _BV(RXCIE1)|(1<<RXEN1)|(1<<TXEN1); |
536 | UART1_CONTROL = _BV(RXCIE1)|(1<<RXEN1)|(1<<TXEN1); |
| 541 | 537 | ||
| 542 |
|
538 | /* Set frame format: asynchronous, 8data, no parity, 1stop bit */ |
| - | 539 | #ifdef URSEL1 |
|
| - | 540 | UCSR1C = (1<<URSEL1)|(3<<UCSZ10); |
|
| - | 541 | #else |
|
| 543 |
|
542 | UCSR1C = (3<<UCSZ10); |
| - | 543 | #endif |
|
| - | 544 | ||
| 544 | }/* uart_init */ |
545 | }/* uart_init */ |
| 545 | 546 | ||
| 546 | 547 | ||
| 547 | /************************************************************************* |
548 | /************************************************************************* |
| 548 | Function: uart1_getc() |
549 | Function: uart1_getc() |