avr/avrlib/UARTを使う
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
[[FrontPage]]
2008/10/20 からのアクセス回数 &counter;
#contents
AVRlibを使った最初の例は、RS232C経由でデバッグプリントを...
役に立つUART通信です。
** ブレッドボートの回路 [#zd056844]
使用するチップは、DIP28ピンのAtmega88です。
ATmega88を選択した理由は、SPOTの外部CPUとして使用されてい...
#ref(8.jpg);
のように結線します。EXO-3は12MHzを取得するために使用しま...
従って、lower fuseは、0xc0です。
AE-UM232RのVOUTは使用せず、GNDのみをAtmega88のGNDと接続し...
** メインプログラム [#o212dbb0]
最初はなんでも、サンプルのコピーからはじめます。
UARTでもそれにならって、avrlib/examples/rprintfをコピーし...
不要な部分をすべて削除して、必要最低限にしたuarttest.cは...
#pre{{
#include "global.h" // include our global settings
#include "uart.h" // include uart function library
#include "rprintf.h" // include printf function library
int main(void)
{
uartInit();
uartSetBaudRate(9600);
rprintfInit(uartSendByte);
rprintf("Hello World\n");
return 0;
}
}}
となります。
- uartInitでUARTを初期化
- uartSetBaudRateでボーレートの設定
- rprintfInitでByte出力関数を渡す
- rprintfは、printfの代わり
*** makefileの変更 [#sa500762]
makefileの変更は、
- MCUをatmega88
- TRGをuartetst
にします。
最終的なmakefileは以下のようになります。
#pre{{
MCU = atmega88
TRG = uarttest
#put your C sourcefiles here
SRC = $(AVRLIB)/buffer.c $(AVRLIB)/uart.c $(AVRLIB)/rprin...
#put additional assembler source file here
ASRC =
#additional libraries and object files to link
LIB =
#additional includes to compile
INC =
#assembler flags
ASFLAGS = -Wa, -gstabs
#compiler flags
CPFLAGS = -g -Os -Wall -Wstrict-prototypes -I$(AVRLIB) -W...
#linker flags
LDFLAGS = -Wl,-Map=$(TRG).map,--cref
########### you should not need to change the following l...
include $(AVRLIB)/make/avrproj_make
###### dependecies, add any dependencies you need here ##...
buffer.o : buffer.c buffer.h
uart.o : uart.c uart.h global.h
uart2.o : uart2.c uart2.h global.h
rprintf.o : rprintf.c rprintf.h
a2d.o : a2d.c a2d.h
timer.o : timer.c timer.h global.h
pulse.o : pulse.c pulse.h timer.h global.h
lcd.o : lcd.c lcd.h global.h
i2c.o : i2c.c i2c.h global.h
spi.o : spi.c spi.h global.h
swpwm.o : swpwm.c swpwm.h global.h
servo.o : servo.c servo.h global.h
swuart.o : swuart.c swuart.h global.h
tsip.o : tsip.c tsip.h global.h
nmea.o : nmea.c nmea.h global.h
vt100.o : vt100.c vt100.h global.h
gps.o : gps.c gps.h global.h
$(TRG).o : $(TRG).c global.h
avrdude: $(TRG).hex
avrdude -c avrispmkII -P usb -p $(MCU) -U flash:w:$(TRG)...
lfuse:
avrdude -c avrispmkII -P usb -p $(MCU) -u -U lfuse:w:0xc...
}}
** 動作確認 [#h5c80641]
ターミナルからjermを起動し、電源を入れると
#pre{{
$ jerm -b 9600 -p none -s 1 -d 8 /dev/cu.usbserial-A5002y...
途中省略
Hello World
}}
と出力されました。
とても簡単にUART通信ができました。
** コメント [#h05b5080]
この記事は、
#vote(おもしろかった[30],そうでもない[20],わかりずらい[10])
皆様のご意見、ご希望をお待ちしております。
- 細かいところですが、Makefile 中に関して その中で avrpro...
- 確かにavrproj_makeでSRCに追加していますね。ここでは、自...
- すばやいレスポンス、ありがとうございます。参考になりま...
- rprintfもそうですが、printf系のルーチンは内部バッファの...
- 了解です。vfprintf() の manual をみるとコンパイルフラグ...
#comment_kcaptcha
終了行:
[[FrontPage]]
2008/10/20 からのアクセス回数 &counter;
#contents
AVRlibを使った最初の例は、RS232C経由でデバッグプリントを...
役に立つUART通信です。
** ブレッドボートの回路 [#zd056844]
使用するチップは、DIP28ピンのAtmega88です。
ATmega88を選択した理由は、SPOTの外部CPUとして使用されてい...
#ref(8.jpg);
のように結線します。EXO-3は12MHzを取得するために使用しま...
従って、lower fuseは、0xc0です。
AE-UM232RのVOUTは使用せず、GNDのみをAtmega88のGNDと接続し...
** メインプログラム [#o212dbb0]
最初はなんでも、サンプルのコピーからはじめます。
UARTでもそれにならって、avrlib/examples/rprintfをコピーし...
不要な部分をすべて削除して、必要最低限にしたuarttest.cは...
#pre{{
#include "global.h" // include our global settings
#include "uart.h" // include uart function library
#include "rprintf.h" // include printf function library
int main(void)
{
uartInit();
uartSetBaudRate(9600);
rprintfInit(uartSendByte);
rprintf("Hello World\n");
return 0;
}
}}
となります。
- uartInitでUARTを初期化
- uartSetBaudRateでボーレートの設定
- rprintfInitでByte出力関数を渡す
- rprintfは、printfの代わり
*** makefileの変更 [#sa500762]
makefileの変更は、
- MCUをatmega88
- TRGをuartetst
にします。
最終的なmakefileは以下のようになります。
#pre{{
MCU = atmega88
TRG = uarttest
#put your C sourcefiles here
SRC = $(AVRLIB)/buffer.c $(AVRLIB)/uart.c $(AVRLIB)/rprin...
#put additional assembler source file here
ASRC =
#additional libraries and object files to link
LIB =
#additional includes to compile
INC =
#assembler flags
ASFLAGS = -Wa, -gstabs
#compiler flags
CPFLAGS = -g -Os -Wall -Wstrict-prototypes -I$(AVRLIB) -W...
#linker flags
LDFLAGS = -Wl,-Map=$(TRG).map,--cref
########### you should not need to change the following l...
include $(AVRLIB)/make/avrproj_make
###### dependecies, add any dependencies you need here ##...
buffer.o : buffer.c buffer.h
uart.o : uart.c uart.h global.h
uart2.o : uart2.c uart2.h global.h
rprintf.o : rprintf.c rprintf.h
a2d.o : a2d.c a2d.h
timer.o : timer.c timer.h global.h
pulse.o : pulse.c pulse.h timer.h global.h
lcd.o : lcd.c lcd.h global.h
i2c.o : i2c.c i2c.h global.h
spi.o : spi.c spi.h global.h
swpwm.o : swpwm.c swpwm.h global.h
servo.o : servo.c servo.h global.h
swuart.o : swuart.c swuart.h global.h
tsip.o : tsip.c tsip.h global.h
nmea.o : nmea.c nmea.h global.h
vt100.o : vt100.c vt100.h global.h
gps.o : gps.c gps.h global.h
$(TRG).o : $(TRG).c global.h
avrdude: $(TRG).hex
avrdude -c avrispmkII -P usb -p $(MCU) -U flash:w:$(TRG)...
lfuse:
avrdude -c avrispmkII -P usb -p $(MCU) -u -U lfuse:w:0xc...
}}
** 動作確認 [#h5c80641]
ターミナルからjermを起動し、電源を入れると
#pre{{
$ jerm -b 9600 -p none -s 1 -d 8 /dev/cu.usbserial-A5002y...
途中省略
Hello World
}}
と出力されました。
とても簡単にUART通信ができました。
** コメント [#h05b5080]
この記事は、
#vote(おもしろかった[30],そうでもない[20],わかりずらい[10])
皆様のご意見、ご希望をお待ちしております。
- 細かいところですが、Makefile 中に関して その中で avrpro...
- 確かにavrproj_makeでSRCに追加していますね。ここでは、自...
- すばやいレスポンス、ありがとうございます。参考になりま...
- rprintfもそうですが、printf系のルーチンは内部バッファの...
- 了解です。vfprintf() の manual をみるとコンパイルフラグ...
#comment_kcaptcha
ページ名:
SmartDoc