Revision 211
broken cardbox, needs to fix the statemachine
rs485_int.c | ||
---|---|---|
16 | 16 |
* Copyright 2009 Kevin Woo <kwoo@2ndt.com> |
17 | 17 |
* |
18 | 18 |
********/ |
19 |
/** @file uart.c
|
|
19 |
/** @file rs485_int.c
|
|
20 | 20 |
* |
21 | 21 |
* @brief Implements UART functionality in hardware |
22 | 22 |
* |
23 | 23 |
* @author Kevin Woo (kwoo) |
24 | 24 |
*/ |
25 | 25 |
|
26 |
#include "uart.h"
|
|
26 |
#include "rs485_int.h"
|
|
27 | 27 |
#include <util/delay.h> |
28 | 28 |
#include <stdint.h> |
29 | 29 |
|
30 | 30 |
uint8_t received_byte; //Byte received |
31 | 31 |
uint8_t byte_ready; //New byte has been received |
32 | 32 |
|
33 |
void init_uart(uint16_t baud) {
|
|
33 |
void rs485_init(uint16_t baud) {
|
|
34 | 34 |
// Set baud rate |
35 | 35 |
UBRRH = (uint8_t)(baud>>8); |
36 | 36 |
UBRRL = (uint8_t)baud; |
... | ... | |
44 | 44 |
// Initialize receive variables |
45 | 45 |
byte_ready = 0; |
46 | 46 |
received_byte = 0x0; |
47 |
|
|
48 |
// Set to receive mode |
|
49 |
rs485_toggle_transmit(TX_OFF); |
|
47 | 50 |
} |
48 | 51 |
|
49 |
int8_t uart_get_byte(uint8_t *output_byte) {
|
|
52 |
int8_t rs485_get_byte(uint8_t *output_byte) {
|
|
50 | 53 |
if (byte_ready) { |
51 | 54 |
byte_ready = 0; |
52 | 55 |
*output_byte = received_byte; |
... | ... | |
56 | 59 |
} |
57 | 60 |
} |
58 | 61 |
|
59 |
void uart_send_byte(uint8_t data) {
|
|
62 |
void rs485_send_byte(uint8_t data) {
|
|
60 | 63 |
//Waits until current transmit is done |
61 | 64 |
while (!(UCSRA & _BV(UDRE))); |
62 | 65 |
|
63 | 66 |
// Enable writes and send |
64 |
uart_toggle_transmit(UART_TX_ON);
|
|
67 |
rs485_toggle_transmit(UART_TX_ON);
|
|
65 | 68 |
UDR = data; |
66 | 69 |
return; |
67 | 70 |
} |
68 | 71 |
|
69 |
void uart_toggle_transmit(uint8_t state) {
|
|
72 |
void rs485_toggle_transmit(uint8_t state) {
|
|
70 | 73 |
if (state == UART_TX_ON) { |
71 | 74 |
PORTD |= TX_EN; |
72 | 75 |
} else { |
... | ... | |
81 | 84 |
|
82 | 85 |
ISR(USART_TX_vect) { |
83 | 86 |
// Re-enable reads |
84 |
uart_toggle_transmit(UART_TX_OFF);
|
|
87 |
rs485_toggle_transmit(UART_TX_OFF);
|
|
85 | 88 |
} |
Also available in: Unified diff