some cleanup and formatting

master
Ondřej Hruška 8 years ago
parent d49fa2ba51
commit b70cf17e53
  1. 10
      README.md
  2. 12
      avr-c-bp.pro
  3. 21
      lib/usart.c
  4. 3
      lib/usart.h
  5. 2
      main.c

@ -39,7 +39,7 @@ You can compile it with `make` and flash with `make flash`.
### Before you can flash
First, check that the `avrdude` options in the file are correct for your system - especially
First, check that the `avrdude` options in the file are correct for your system - especially
the device and speed.
```ini
@ -52,7 +52,7 @@ PROG_TYPE = arduino
PROG_ARGS = -c $(PROG_TYPE) -p $(MCU) -b $(PROG_BAUD) -P $(PROG_DEV)
```
- Adjust `PROG_DEV` to the device your board is connected to. On Linux it's usually
- Adjust `PROG_DEV` to the device your board is connected to. On Linux it's usually
`/dev/ttyUSB0`, but it can also be `/dev/ttyACM0` or something else. On Mac, it'll be
`/dev/cu.xxx`. On Windows it's some `COMx`.<br>
Linux and Mac users can use `ls /dev` to see their devices. Windows users will find
@ -71,4 +71,8 @@ created by the compiler before linking) to the `OBJS` list in the Makefile.
## Notes
- Since the Arduino Uno has a quirk where Double Speed Asynchronous Mode for USART is enabled by default, we made sure to disable this. If this mode is enabled it means that the USART baud rate is doubled, so if you were using a baud rate of `9200` in the code, you'd have to use a baud rate of 19200 in your terminal. We disabled this to keep things consistent, and because it has no real benefit. If you wish to turn this on however, you can do so by using `usart_set_2x(true);`
- The **Arduino UNO** bootloader has a quirk where `Double Speed Asynchronous Mode` for USART
is enabled by default, so if you set your baud rate to 9600, you'd really get 19200.<br>
We correct this in the `usart_init()` function to keep things consistent and to avoid
confusion.<br>
*If you wish to turn this on* however, you can do so by using `usart_set_2x(true)`.

@ -12,21 +12,21 @@ DEFINES += __AVR_ATmega328P__ F_CPU=16000000UL
DISTFILES += \
style.astylerc \
Makefile \
README.md \
LICENSE
README.md \
LICENSE
HEADERS += \
lib/calc.h \
lib/iopins.h \
lib/usart.h \
lib/nsdelay.h \
lib/spi.h
lib/nsdelay.h \
lib/spi.h
SOURCES += \
lib/iopins.c \
main.c \
lib/usart.c \
lib/spi.c
lib/usart.c \
lib/spi.c
# === Flags for the Clang code model===
#

@ -26,16 +26,14 @@ void usart_init(uint16_t ubrr)
UCSR0C = (0b11 << UCSZ00);
}
void usart_set_2x(bool set)
/** Set Double Speed Asynchronous mode */
void usart_set_2x(bool set)
{
// Turn on Double Speed Asynchronous Mode
if (set)
sbi(UCSR0A, U2X0);
// Turn off Double Speed Asynchronous Mode
else
cbi(UCSR0A, U2X0);
set_bit(UCSR0A, U2X0, set);
}
/** Send byte over USART */
void usart_tx(uint8_t data)
{
@ -59,8 +57,7 @@ uint8_t usart_rx(void)
/** Send string over USART */
void usart_puts(const char* str)
{
while (*str)
{
while (*str) {
usart_tx(*str++);
}
}
@ -70,8 +67,7 @@ void usart_puts(const char* str)
void usart_puts_P(const char* str)
{
char c;
while ((c = pgm_read_byte(str++)))
{
while ((c = pgm_read_byte(str++))) {
usart_tx(c);
}
}
@ -81,8 +77,7 @@ void usart_puts_P(const char* str)
void usart_flush_rx(void)
{
uint8_t dummy;
while (bit_is_high(UCSR0A, RXC0))
{
while (bit_is_high(UCSR0A, RXC0)) {
dummy = UDR0;
}
}

@ -35,12 +35,15 @@ enum {
/** Init UART with a UBRR value - can use the BAUD_* constants for 16 MHz */
void usart_init(uint16_t ubrr);
/** Set Double Speed Asynchronous mode on or off */
void usart_set_2x(bool set);
/** Check if there's a byte in the RX register */
#define usart_rx_ready() bit_is_high(UCSR0A, RXC0)
/** Check if USART is ready to accept new byte to send */
#define usart_tx_ready() bit_is_high(UCSR0A, UDRE0)

@ -26,7 +26,7 @@ ISR(USART_RX_vect)
void main()
{
usart_init(BAUD_9600);
usart_init(BAUD_115200);
usart_isr_rx_enable(true); // enable RX interrupt handler
// configure pins

Loading…
Cancel
Save