USB-IOã«ä»£ãããã®
以åãUSB-IOã¨ãã製åãç´¹ä»ããã(http://d.hatena.ne.jp/yaneurao/20041109)
ç§ã¯é·ããé»åå·¥ä½ã§USB-IOãæç¨ãã¦ããã®ã ãã1ãã¤ããã¤ãã¼ã¿ãéä¿¡ããã¨1ç§éã®ã¹ã«ã¼ãããã¯200ãã¤ã/ç§ãããããåºãªãã1600bpsãªã®ã§ãéä¿¡ã¨ãã¦ã¯ããªãé ãé¨é¡ã«å ¥ãã ããã
ä»åãéä¿¡é¨åã®é度ãããå°ãè¦æ±ãããæ¡ä»¶ããã£ãã®ã§ãFT232ã§ä½ã¨ãããããã¨æã£ã¦ããã®ã ãããã¾ãã¾ç«ã¡å¯ã£ã大éªæ¥æ¬æ©ã®ãã¸ããã§ABL-168ã¨ããUSBãã¼ããã¼ãã¼ä»ãã®AVRãã¤ã³ã³(è¼ã£ã¦ããã®ã¯ATmega168)ãã¼ããè¦ã¦ããããFT232RLãè¼ã£ã¦ãããPCå´ããã¯ä»®æ³COMãã¼ãçµç±ã§AVRã«ã¢ã¯ã»ã¹åºæ¥ãã
FT232RLã¨ATmega168ãè¼ã£ã¦ãã¦ãUSBã±ã¼ãã«ããã©ã¤ããåè·¯å³ä»ãããã¼ããã¼ãã¼æ¸ãè¾¼ã¿æ¸ãAVRãã¤ã³ã³ã¸èªåã®ä½ã£ãããã°ã©ã ã転éããããã®ã½ãããã¤ãã¦ã¦ãçµã¿ç«ã¦æ¸ã¿ãªã®ã«2,700åï¼*1ãããã¯ç ´æ ¼ã®å®ãã ã¨æããç§ã¯ãã¨ã§300åã»ã©è²·ã£ã¦ããäºå®ã ã(ã¡ãªã¿ã«å ±ç«ã¨ã¬ã·ã§ããããã¤ã³ã¿ã¼ãããé販ã§ãè²·ããâhttp://eleshop.kyohritsu.com/)
ä»åã¯ãC#ãããã®AVRãã¤ã³ã³ã¨USBçµç±ã§ãã¼ã¿ã®ããã¨ããããæ¹æ³ãæ¸ãã¦ããã
åè·¯å³ã®FT232RLã®ã¨ãããè¦ãã¨TXD,RXDãAVRã®RXD,TXDã«çµç·ããã¦ãããã¨ãããããã¤ã¾ããAVRå´ã®USARTæ©è½ãå©ç¨ããã°ä½ãèããã«1ãã¤ããã¼ã¿ãéåä¿¡åºæ¥ãã以ä¸ã®ããã°ã©ã ã¯å²ãè¾¼ã¿ã使ããåä¿¡ãããã¡ãã1ãã¤ãåãåºãã¦ããã®æåã®ãã£ã©ã¯ã¿ã³ã¼ãã«1ã足ãããã®ãéä¿¡ãããã¡ã«è¿ãããã°ã©ã ã§ããã
Windowsä»å±ã®ãã¤ãã¼ã¿ã¼ããã«ã§æ¥ç¶ãã¦ãecho backããããã¨ã確èªããã
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>#define FOSC 20000000 // 20MHz
#define BAUD 38400
#define MYUBRR FOSC/16/BAUD-1/* sioè¨å® */
// 38400bps,ãã¼ã¿ããã8,ããªãã£ãªã,ã¹ãããããã1,ããã¼å¶å¾¡ãªãã
void sio_init(unsigned int ubrr){
UBRR0H = (unsigned char)(ubrr>>8); // ãã¼ã¬ã¼ãä¸ä½8bit
UBRR0L = (unsigned char)ubrr; // ãã¼ã¬ã¼ãä¸ä½8bit
UCSR0B = (1<<RXEN0) | (1<<TXEN0); // éå信許å¯,å²ãè¾¼ã¿ã¯ä¸è¨±å¯
UCSR0C = (3<<UCSZ00); // stopbit 1bit , 8bitéä¿¡
}void wait_for_sending()
{
loop_until_bit_is_set(UCSR0A,UDRE0); // éä¿¡ãã¼ã¿ã¬ã¸ã¹ã¿ç©ºãã¾ã§å¾ æ©
}int is_received()
{
return UCSR0A & (1<<RXC0);
}int main(void){
sio_init(MYUBRR); // SIOè¨å®
for(;;)
{
if (is_received())
{
// UDR0 = UDR0; // echo back
UDR0 = UDR0+1; // ä¸æååãããã¦ã¿ã
wait_for_sending();
}
}
}
C#ããUSBçµç±ã§ãã®AVRãéä¿¡ããã«ã¯ãä»®æ³COMãã¼ããªã®ã§SerialPortã¯ã©ã¹ãç¨ããã°ç°¡åã ããªããéä¿¡é度ã¯57600bpsãéçã®ããã ã
port = new SerialPort("COM10");
port.Parity = Parity.None;
port.BaudRate = 38400;
port.StopBits = StopBits.One;
port.Open();char[] buffer = new char[4]{'A','B','C','D'};
port.Write(buffer, 0, 4); // éä¿¡ãããã¡ã«4ãã¤ãæ¸ãè¾¼ã¿
// 以ä¸ã¯ãä¾ãã°ãã¨ããã³ã¼ã
int read_size = port.BytesToRead; // ãããã¡ã«åä¿¡ãã¦ãããã¼ã¿ãµã¤ãº
if (read_size != 0)
{
port.Read(buffer, 0, 1); // åä¿¡ãããã¡ãã1æåèªã¿è¾¼ã¿
Console.WriteLine( buffer[0] );
}
1ãã¤ããã¤SerialPort.Writeã§éä¿¡ããå ´åã®ã¹ã«ã¼ãããã¯800ãã¤ã/ç§ç¨åº¦ãUSB-IOã®4åãããéãã
4ãã¤ããã¤éä¿¡ããå ´åã®ã¹ã«ã¼ãããã¯ãã®3åããããããç¨åº¦ã¾ã¨ãã¦éä¿¡ããã»ããã¹ã«ã¼ãããã¯ä¸ãããç¡è«ãBaudRate以ä¸ã«ã¯ãªããªããã
ãããªããã§ãFT232RLã®å ã«AVRãã¤ã³ã³ãä»å±ãã¦ããã¨è¤éãªå¦çã§ãããã§ããããã¨ãåºæ¥ãããè¨èªã¯Cã§éçºã§ããããAVRã©ã¤ã¿ã¼ã¯ä¸è¦ã ããATmega168ãªãI/Oã¯16æ¬ä»¥ä¸ãããã20MHzã®(ã¯ã³ããããã¤ã³ã³ã¨ãã¦ã¯)é«éåä½ã ããå¤é¨é»æºããé»æºãã¨ããUSBããã¨ããã¯åºæ¿ä¸ã®ã¸ã£ã³ãã¼ã§å¤æ´ã§ããããã«ãªã£ã¦ããããçµã¿ç«ã¦æ¸ã¿ã ããFLASHãã¤ã³ã³ã ããããã°ã©ã ã¯ä¸åº¦æ¸ãè¾¼ãã§ãã¾ãã°é»æºãåã£ã¦ãæ®ã£ã¦ããããã®kitã¯æãåºãç©ã ã¨æããUSBçµç±ã§ãã¼ã¿ãéåä¿¡ãããã¨ãã«ãå§ãã
ä¸ã§ç´¹ä»ããABL-168ã¯ATmega168ãè¼ã£ã¦ãã¦ãATmega168ã¯16KB(8Kã¯ã¼ã)ã®ãã©ãã·ã¥ã¡ã¢ãªããããçµã¿è¾¼ã¿ç¨éãªãããã§ãååãªå®¹éã ããããã®ä¸ä½è£½åã¨ãã¦ABL-128ã¨ããã®ããã¸ããã§å£²ããã¦ããã(å ±ç«ã¨ã¬ã·ã§ãããããè²·ãã)ããã¡ãã¯ATmega128ãè¼ã£ã¦ãã¦ã3,900åãATmega128ã¯ã¦ã¼ã¶ã¼I/Oã50æ¬ä»¥ä¸ããã128KB(64Kã¯ã¼ã)ã®ãã©ãã·ã¥ã¡ã¢ãªããããABL-128ãåè·¯å³ã確èªããã¨ãããABL-168ã¨åãããã«FT232RLã¨æ¥ç¶ããã¦ããã®ã§ä¸ã§ç´¹ä»ããæ¹æ³ã§PCããã¢ã¯ã»ã¹ã§ããã
ãã¨ãè¤æ°ã®ABL-168ã1PCã«æ¥ç¶ãããã¦ãã¦ãæ¸ãã¦ã¿ãã®ã§èå³ã®ãã人ã¯ã©ããã
ã»FT232RLã®å¨è¾º
http://d.hatena.ne.jp/yaneurao/20080630
â ãé¢é£è¨äº
ãã¾ããPICãããã¦AVRã«ç§»è¡ãã¹ã10ã®çç±
http://d.hatena.ne.jp/yaneurao/20080228
JTAGICE mkIIã¨ICD2ã®clone
http://d.hatena.ne.jp/yaneurao/20080229