{"id":127,"date":"2019-08-15T10:15:27","date_gmt":"2019-08-15T01:15:27","guid":{"rendered":"http:\/\/stg-kanta.artful.co.jp\/?p=127"},"modified":"2019-08-15T10:15:27","modified_gmt":"2019-08-15T01:15:27","slug":"arduino-and-rs485-2","status":"publish","type":"post","link":"https:\/\/horiokanta.com\/ja\/arduino-and-rs485-2\/","title":{"rendered":"Arduino\u3068RS485"},"content":{"rendered":"<p><a href=\"http:\/\/horiokanta.com\/control-panel\/wp-content\/uploads\/2019\/08\/rs485_sample.png\"><img loading=\"lazy\" src=\"http:\/\/horiokanta.com\/control-panel\/wp-content\/uploads\/2019\/08\/rs485_sample-1024x581.png\" alt=\"\" width=\"1024\" height=\"581\" class=\"img-fluid d-block mx-auto\" \/><\/a><\/p>\n<h2>RS485\u3068\u9001\u53d7\u4fe1\u306e\u5207\u308a\u66ff\u3048<\/h2>\n<p>RS485\u901a\u4fe1\u306f\u534a\u4e8c\u91cd\u901a\u4fe1\u306a\u306e\u3067\u3001\u540c\u3058\u901a\u4fe1\u30e9\u30a4\u30f3\u3067\u9001\u4fe1\u3068\u53d7\u4fe1\u4e21\u65b9\u3092\u884c\u3044\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001RS485\u7528\u306e\u30c9\u30e9\u30a4\u30d0IC\u306f\u9001\u4fe1\u3068\u53d7\u4fe1\u3069\u3061\u3089\u3082\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u3066\u3001\u9001\u4fe1\u6642\u306e\u307f\u9001\u4fe1\u6a5f\u3092\u30aa\u30f3\uff08\u53d7\u4fe1\u6a5f\u3092\u30aa\u30d5\uff09\u3001\u9001\u4fe1\u304c\u7d42\u308f\u3063\u305f\u3089\u3059\u3050\u306b\u9001\u4fe1\u6a5f\u3092\u30aa\u30d5\u306b\u3057\u3066\u3001\u53d7\u4fe1\u6a5f\u3092\u30aa\u30f3\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u5207\u308a\u66ff\u3048\u3092\u3001\u4e0a\u8a18\u306e\u56de\u8def\u56f3\u3067\u306f\u300cTXDEN\u300d\u30d4\u30f3\u304c\u62c5\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\nArduino\u4e0a\u3067\u30011\u79d2\u306b1\u56de\u3001100\u30d0\u30a4\u30c8\u3092\u9001\u308b\u30b9\u30b1\u30c3\u30c1\u3092\u66f8\u3044\u3066\u3001\u3053\u308c\u306bTXDEN\u30d4\u30f3\u306e\u51e6\u7406\u3092\u52a0\u3048\u308b\u3053\u3068\u3092\u8003\u3048\u307e\u3059\u3002<\/p>\n<pre><code>\n#define TXDEN\t3\n\nvoid setup()\n{\n\tpinMode(TXDEN, OUTPUT);\n\tSerial.begin(9600);\n}\n\nvoid loop()\n{\n\tbyte txData[100];\n\tSerial.write(txData,100);\n\n\tdelay(1000);\n}\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u56de\u8def\u56f3\u306eIC\u3067\u306fTXDEN\u3092HIGH\u306b\u3059\u308b\u3068\u9001\u4fe1\u6a5fON\/\u53d7\u4fe1\u6a5fOFF\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u30b7\u30ea\u30a2\u30eb\u3092\u9001\u4fe1\u3059\u308b\u524d\u306bTXDEN\u30d4\u30f3\u3092HIGH\u306b\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u304c\u3001\u9001\u4fe1\u306e\u5b8c\u4e86\u6642\u304c\u554f\u984c\u306b\u306a\u308a\u307e\u3059\u3002Serial.print\u3084Serial.write\u306f\u30cf\u30fc\u30c9\u30a6\u30a7\u30a2\u3067\u884c\u308f\u308c\u308b\u305f\u3081\u3001\u4f8b\u3048\u3070<br \/>\n<code><br \/>\ndigitalWrite(TXDEN, HIGH);<br \/>\nSerial.write(txData,100);<br \/>\ndigitalWrite(TXDEN, LOW);<br \/>\n<\/code><br \/>\n\u3068\u66f8\u3044\u3066\u3082\u3001\u30b9\u30b1\u30c3\u30c1\u306f\u30b7\u30ea\u30a2\u30eb\u306e\u9001\u4fe1\u3092\u30cf\u30fc\u30c9\u30a6\u30a7\u30a2\u306b\u6307\u4ee4\u3059\u308b\u3060\u3051\u3067\u3059\u3050\u306b\u6b21\u306e\u884c\u306e\u5b9f\u884c\u3092\u59cb\u3081\u3066\u3057\u307e\u3044\u3001\u9001\u4fe1\u4e2d\u306b\u3082\u95a2\u308f\u3089\u305aTXDEN\u304cLOW\u306b\u623b\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u3053\u308c\u3092\u3046\u307e\u304f\u3084\u308b\u306b\u306f\u3001\u30b7\u30ea\u30a2\u30eb\u306e\u9001\u4fe1\u304c\u7d42\u308f\u3063\u305f\u3089\u5272\u8fbc\u307f\u3092\u767a\u751f\u3055\u305b\u3001\u305d\u306e\u4e2d\u3067TXDEN\u3092LOW\u306b\u623b\u3059\u3088\u3046\u306b\u3057\u307e\u3059\u3002\u9001\u4fe1\u5b8c\u4e86\u3067\u5272\u8fbc\u307f\u3092\u767a\u751f\u3055\u305b\u308b\u90e8\u5206\u306f\u3001MCU\u306e\u7a2e\u985e\u306b\u3088\u3063\u3066\u7570\u306a\u308a\u307e\u3059\u3002\n<\/p>\n<h2>MCU\u3054\u3068\u306e\u30d7\u30ed\u30b0\u30e9\u30e0<\/h2>\n<h3>Arduino UNO (ATmega328)<\/h3>\n<p>UNO\u4ee5\u5916\u3067\u3082\u3001ATmega328\u3092\u4f7f\u3063\u305f\u30dc\u30fc\u30c9\u3067\u3042\u308c\u3070\u540c\u3058\u3067\u3059\u3002<br \/>\n<code><br \/>\nUCSR0B |= (1&lt;&lt;TXCIE0);     \/\/ TX Complete Interrupt Enable 0<br \/>\n<\/code><br \/>\n\u3053\u306e\u8a2d\u5b9a\u3092\u4e8b\u524d\u306b\u884c\u3063\u3066\u304a\u304f\u3053\u3068\u3067\u3001\u30b7\u30ea\u30a2\u30eb\u306e\u9001\u4fe1\u5b8c\u4e86\u6642\u306b\u5272\u8fbc\u307f\u304c\u767a\u751f\u3059\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><code><br \/>\nISR    (USART_TX_vect) {<br \/>\n       digitalWrite(TXDEN, LOW);<br \/>\n}<br \/>\n<\/code><br \/>\n\u3053\u3053\u304c\u5b9f\u969b\u306b\u5272\u8fbc\u307f\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306b\u5b9f\u884c\u3055\u308c\u308b\u90e8\u5206\uff08\u5272\u308a\u8fbc\u307f\u30cf\u30f3\u30c9\u30e9\uff09\u3067\u3059\u3002<\/p>\n<p>\u4e0a\u8a18\u306e\u30b9\u30b1\u30c3\u30c1\u306b\u3053\u308c\u3089\u306e\u51e6\u7406\u3092\u66f8\u304d\u52a0\u3048\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><code>\n#define TXDEN\t3\n\nvoid setup()\n{\n\tUCSR0B |= (1&lt;&lt;TXCIE0);     \/\/ TX Complete Interrupt Enable 0\n\tpinMode(TXDEN, OUTPUT);\n\tSerial.begin(9600);\n}\n\nISR (USART_TX_vect)\n{\n       digitalWrite(TXDEN, LOW);\n}\n\nvoid loop()\n{\n\tbyte txData[100];\n\tdigitalWrite(TXDEN, HIGH);\n\tSerial.write(txData,100);\n\n\tdelay(1000);\n}\n<\/code><\/pre>\n<\/p>\n<h3>Arduino Leonardo (ATmega32u4)<\/h3>\n<p>\nLeonardo\u3067\u306fSerial\u3067\u306f\u306a\u304f\u3066Serial1\u3092\u4f7f\u3044\u307e\u3059\u3002\u4f7f\u7528\u3059\u308b\u30ec\u30b8\u30b9\u30bf\u540d\u3082\u5408\u308f\u305b\u3066\u5c11\u3057\u7570\u306a\u308a\u307e\u3059\u3002\n<\/p>\n<p><code><br \/>\nUCSR1B |= (1&lt;&lt;TXCIE1);     \/\/ TX Complete Interrupt Enable 1<\/p>\n<p>ISR    (USART1_TX_vect) {<br \/>\n       digitalWrite(TXDEN, LOW);<br \/>\n}<br \/>\n<\/code><br \/>\n\u30b9\u30b1\u30c3\u30c1\u4f8b<\/p>\n<pre><code>\n#define TXDEN\t3\n\nvoid setup()\n{\n\tUCSR1B |= (1&lt;&lt;TXCIE1);     \/\/ TX Complete Interrupt Enable 1\n\tpinMode(TXDEN, OUTPUT);\n\tSerial1.begin(9600);\n}\n\nISR (USART1_TX_vect)\n{\n       digitalWrite(TXDEN, LOW);\n}\n\nvoid loop()\n{\n\tbyte txData[100];\n\tdigitalWrite(TXDEN, HIGH);\n\tSerial1.write(txData,100);\n\n\tdelay(1000);\n}\n<\/code><\/pre>\n<h3>Arduino Zero\/M0 (ATMSAD21G18A)<\/h3>\n<p>\nSAMD\u3068\u547c\u3070\u308c\u308b\u3053\u308c\u3089\u306e\u30dc\u30fc\u30c9\u306f\u69cb\u9020\u304c\u7d50\u69cb\u9055\u3044\u3001Serial\u306e\u5272\u308a\u8fbc\u307f\u30cf\u30f3\u30c9\u30e9\u304cArduino\u672c\u4f53\u306e\u65b9\u3067\u4f7f\u308f\u308c\u3066\u3044\u308b\u3088\u3046\u3067\u3001\u30b9\u30b1\u30c3\u30c1\u306e\u5074\u304b\u3089\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002\u304c\u3001SAMD\u306f\u30b7\u30ea\u30a2\u30eb\u30dd\u30fc\u30c8\u3092\u8907\u6570\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3001Arduino\u672c\u4f53\u3067\u4f7f\u308f\u308c\u3066\u3044\u306a\u3044\u65b0\u3057\u3044\u30b7\u30ea\u30a2\u30eb\u30dd\u30fc\u30c8\u3092\u4f5c\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3053\u306e\u554f\u984c\u3092\u56de\u907f\u3057\u307e\u3059\u3002\u305f\u3060\u3057\u901a\u5e38\u306eTX\/RX\u30d4\u30f3\u3068\u306f\u5225\u306e\u30d4\u30f3\u3092\u4f7f\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u8272\u3005\u306a\u8a2d\u5b9a\u65b9\u6cd5\u304c\u3042\u308a\u5f97\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u3053\u3067\u306f<br \/>\nD2 : TX<br \/>\nD3 : RX<br \/>\nD4 : TXDEN<br \/>\n\u3068\u3044\u3046\u8a2d\u5b9a\u3067\u8003\u3048\u3066\u307f\u307e\u3059\u3002\u5927\u5909\u3084\u3084\u3053\u3057\u3044\u306e\u3067\u3059\u304czero\u3068M0\u306f\u3001D2\u30d4\u30f3\u3068D4\u30d4\u30f3\u304c\u5165\u308c\u66ff\u308f\u3063\u3066\u3044\u308b\u305f\u3081\u3001\u30b9\u30b1\u30c3\u30c1\u3082\u7570\u306a\u3063\u3066\u304d\u307e\u3059\u3002<br \/>\n\u307b\u304b\u306bMKR zero\u306a\u3069\u540c\u3058MCU\u306e\u30dc\u30fc\u30c9\u3082\u540c\u69d8\u306b\u3067\u304d\u308b\u3068\u601d\u308f\u308c\u307e\u3059\u304c\u3001\u30d4\u30f3\u914d\u7f6e\u306f\u305d\u308c\u305e\u308c\u7570\u306a\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u306e\u3067\u3001\u6539\u5909\u304c\u5fc5\u8981\u305d\u3046\u3067\u3059\u3002\n<\/p>\n<h4> Arduino M0<\/h4>\n<p><pre><code>\n\/\/ Arduino M0\n\/\/ D2 PA08 SERCOM2\/PAD[0]\nUart Serial3 (&sercom2, 3, 2, SERCOM_RX_PAD_1, UART_TX_PAD_0); \n#define txDenPin 4\nvoid SERCOM2_Handler()\n{   \n  Serial3.IrqHandler();\n  if (SERCOM2->USART.INTFLAG.bit.TXC)\n  {\n    digitalWrite(txDenPin, LOW);\n    SERCOM2->USART.INTFLAG.bit.TXC = 1;\n  }\n}\n\nvoid setup() {\n  pinMode(txDenPin, OUTPUT);\n  Serial3.begin(9600);\n  pinPeripheral(3, PIO_SERCOM_ALT);\n  pinPeripheral(2, PIO_SERCOM_ALT);\n  SERCOM2->USART.INTENSET.bit.TXC = 1;\n}\n\nvoid loop()\n{\n\tbyte txData[100];\n\tdigitalWrite(txDenPin, HIGH);\n\tSerial3.write(txData,100);\n\n\tdelay(1000);\n}\n<\/code><\/pre>\n<\/p>\n<h4> Arduino zero<\/h4>\n<p><pre><code>\n\/\/ Arduino Zero\n\/\/ D2 PA14 SERCOM2\/PAD[2]\nUart Serial3 (&sercom2, 3, 2, SERCOM_RX_PAD_1, UART_TX_PAD_2); \n#define txDenPin 4\nvoid SERCOM2_Handler()\n{   \n  Serial3.IrqHandler();\n  if (SERCOM2->USART.INTFLAG.bit.TXC)\n  {\n    digitalWrite(txDenPin, LOW);\n    SERCOM2->USART.INTFLAG.bit.TXC = 1;\n  }\n}\n\nvoid setup() {\n  pinMode(txDenPin, OUTPUT);\n  Serial3.begin(9600);\n  pinPeripheral(3, PIO_SERCOM_ALT);\n  pinPeripheral(2, PIO_SERCOM);\n  SERCOM2->USART.INTENSET.bit.TXC = 1;\n}\n\nvoid loop()\n{\n\tbyte txData[100];\n\tdigitalWrite(txDenPin, HIGH);\n\tSerial3.write(txData,100);\n\n\tdelay(1000);\n}\n<\/code><\/pre>\n<\/p>\n<h3>Arduino Due (SAM3X8E)<\/h3>\n<p>\u3053\u306eMCU\u306fRS485\u30e2\u30fc\u30c9\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308a\u3001\u5272\u8fbc\u307f\u51e6\u7406\u3092\u884c\u308f\u306a\u304f\u3066\u3082\u3001\u9001\u4fe1\u4e2d\u306e\u6642\u3060\u3051\u81ea\u52d5\u3067\u30d4\u30f3\u3092HIGH\u306b\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002RTS\u3068\u3044\u3046\u6a5f\u80fd\u3092\u30d4\u30f3\u306b\u5272\u308a\u4ed8\u3051\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u5b9f\u73fe\u3057\u307e\u3059\u3002<br \/>\nTX1(D18) : TX<br \/>\nRX1(D19) : RX<br \/>\nD2 : TXDEN<br \/>\n\u3068\u3044\u3046\u8a2d\u5b9a\u306e\u30b9\u30b1\u30c3\u30c1\u4f8b\u3067\u3059\u3002<\/p>\n<pre><code>\n#define txDenPin 2\nvoid setup() {\n  pinMode(txDenPin , OUTPUT);\n  Serial1.begin(9600);\n  USART0-&gt;US_MR |= 0x01;\n  REG_PIOB_ABSR &= ~PIO_ABSR_P25;   \/\/ select peripheral A\n  REG_PIOB_PDR |= PIO_PDR_P25;      \/\/ Disable the GPIO and switch to the peripheral\n}\n\nvoid loop() {\n  byte txData[100];\n  Serial1.write(txData,20);\n  delay(1000);\n}\n<\/code><\/pre>\n<\/p>\n<p><!--\n\n\n<h2>\u4f7f\u3048\u308b\u30c9\u30e9\u30a4\u30d0IC\u306e\u4f8b<\/h2>\n\n\n\n\n<p>\u4ee5\u4e0b\u306f\u4e00\u4f8b\u3067\u3059\u3002\u52d5\u4f5c\u96fb\u5727\u306e\u307b\u304b\u3001\u52d5\u4f5c\u30b9\u30d4\u30fc\u30c9\u3082\u91cd\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n\n<h3>5V<\/h3>\n\n\n\n\n\n<h3>3.3V<\/h3>\n\n\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>RS485\u3068\u9001\u53d7\u4fe1\u306e\u5207\u308a\u66ff\u3048 RS485\u901a\u4fe1\u306f\u534a\u4e8c\u91cd\u901a\u4fe1\u306a\u306e\u3067\u3001\u540c\u3058\u901a\u4fe1\u30e9\u30a4\u30f3\u3067\u9001\u4fe1\u3068\u53d7\u4fe1\u4e21\u65b9\u3092\u884c\u3044\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001RS485\u7528\u306e\u30c9\u30e9\u30a4\u30d0IC\u306f\u9001\u4fe1\u3068\u53d7\u4fe1\u3069\u3061\u3089\u3082\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u3066\u3001\u9001\u4fe1\u6642\u306e\u307f\u9001\u4fe1\u6a5f\u3092\u30aa\u30f3\uff08\u53d7\u4fe1\u6a5f\u3092\u30aa\u30d5\uff09\u3001\u9001\u4fe1\u304c\u7d42\u308f\u3063\u305f\u3089\u3059\u3050\u306b\u9001\u4fe1\u6a5f\u3092\u30aa\u30d5\u306b\u3057\u3066\u3001\u53d7\u4fe1\u6a5f\u3092\u30aa\u30f3\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u5207\u308a\u66ff\u3048\u3092\u3001\u4e0a\u8a18\u306e\u56de\u8def\u56f3\u3067\u306f\u300cTXDEN\u300d\u30d4\u30f3\u304c\u62c5\u3063\u3066\u3044\u307e\u3059\u3002 Arduino\u4e0a\u3067\u30011\u79d2\u306b1\u56de\u3001100\u30d0\u30a4\u30c8\u3092\u9001\u308b\u30b9\u30b1\u30c3\u30c1\u3092\u66f8\u3044\u3066\u3001\u3053\u308c\u306bTXDEN\u30d4\u30f3\u306e\u51e6\u7406\u3092\u52a0\u3048\u308b\u3053\u3068\u3092\u8003\u3048\u307e\u3059\u3002 #define TXDEN 3 void setup() { pinMode(TXDEN, OUTPUT);  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":138,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"120"},"categories":[4],"tags":[6,8,13,20],"_links":{"self":[{"href":"https:\/\/horiokanta.com\/wp-json\/wp\/v2\/posts\/127"}],"collection":[{"href":"https:\/\/horiokanta.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/horiokanta.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/horiokanta.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/horiokanta.com\/wp-json\/wp\/v2\/comments?post=127"}],"version-history":[{"count":0,"href":"https:\/\/horiokanta.com\/wp-json\/wp\/v2\/posts\/127\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/horiokanta.com\/wp-json\/wp\/v2\/media\/138"}],"wp:attachment":[{"href":"https:\/\/horiokanta.com\/wp-json\/wp\/v2\/media?parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/horiokanta.com\/wp-json\/wp\/v2\/categories?post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/horiokanta.com\/wp-json\/wp\/v2\/tags?post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}