AVR GSM ボード用の簡単なシリアル通信コードを教えてください。マイクロコントローラーのプログラミングを始めたばかりで、コードは正常にビルドされるため正しいかどうかわかりませんが、ボード上で書き込むと機能しません。通信ポートに接続できる C# アプリケーションがあり、シリアル通信をテストしたいと考えています。ボードのモデルはhttps://www.olimex.com/Products/AVR/Development/AVR-GSM/ です。MCU のコードは次のとおりです。
#include <avr/io.h>
#include <stdio.h>
#include <stdbool.h>
#define BAUD 115200
#define MYUBRR F_CPU/16/BAUD-1
void usart_init(uint16_t ubrr);
char usart_getchar( void );
void usart_putchar( char data );
void usart_pstr(char *s);
unsigned char kbhit(void);
int main( void )
{
// configure PORTA as output
DDRA = 0xFF;
// setup PORTB data direction as an input
DDRB = 0;
// make sure it is high impedance and will not source
PORTB = 0;
// fire up the usart
usart_init ( MYUBRR );
// dump some strings to the screen at power on
usart_pstr("Welcome!\n\r");
usart_pstr("Type in a character, and I will transpose it up by 1:\n\r");
// main loop
while(true) {
// if a key has been pressed, then process it
if(kbhit()) {
usart_putchar(usart_getchar() + 1);
}
// map the PINB inputs to the PORTA outputs
PORTA = PINB;
// a little humor is always good, PB0 gets the user yelled at
if(bit_is_clear(PINB,PB0)) {
usart_pstr("OUCH! Stop poking me!\n\r");
}
}
return 0;
}