/* * Author: Jake Goodwin * Date: 2023 * Description: Small library to communicate with the AT-09 bluetooth module. */ #include #include #include #include #include "avr_usart.h" //############################# //Globals //############################# int main() { led_blink(); led_blink(); led_blink(); _delay_ms(1000); _delay_ms(1000); init_usart0(); //enable interrupts sei(); uint8_t buf_len = 12; //unsigned char data[12] = "snd 12chars\0"; //unsigned char data[1] = "A"; unsigned char data[1] = "B"; while(1) { //serial0_write(data, buf_len); if(data[0] == 0) { data[0] = '!'; } tx_usart0(data[0]); //serial0_read(data, buf_len); //data = rx_usart0(); serial0_flush_rxbuf(); serial0_read_with_err_checking(data, 1); unsigned char data[] = "AT+WAKE"; while(1) { _delay_ms(1000); //led_blink(); for(uint8_t i = 0; i < 7; i++) { tx_usart0(data[i]); } } return 0; } //############################# //FUNCTIONS //############################# /* * Input: None * Output: None * Description: init usart0 hardware in async mode */ void init_usart0(void) { //DDRB |= (1<>8); //UBRR0L |= (uint8_t) BT_UBRR; UBRR0H |= (uint8_t) (0x33>>8); UBRR0L |= (uint8_t) 0x33; //Enable recv and Transmit pins, overrides other uses. //IN the usart control and status register 0B UCSR0B = (1< 300bps * 103 --> 600bps * 51 --> 1200bps * 25 --> 2400bps * 12 --> 4800bps * 6 --> 9600bps !!! 7% error rate */ void serial0_set_baud(uint8_t baud) { UBRR0H |= (uint8_t) (baud>>8); UBRR0L |= (uint8_t) baud; } /* * Input: None * Output: None * Description: Toggles the pin for the LED indicator. */ static void led_blink(void) { //Set the DDR for output. DDRC |= (1<