SC16IS750 | ATmega328 | 備考 |
---|---|---|
i2c-SPI | GND | i2c/SPIの切り替え |
A0-CS | CS | スケッチ上でピンを指定 |
A1-SI | MOSI | |
NC-SO | MISO | |
SCL-SCK | SCK | |
SDA-VSS | GND | |
/IRQ | N/C | 何処にも繋がっていない |
RESET | N/C | 基板上でPullUpされている |
VIN | 5V | |
GND | GND |
#include <SPI.h> #include <Wire.h> #include <SC16IS750.h> #include <string.h> SC16IS750 spiuart = SC16IS750(SC16IS750_PROTOCOL_SPI,6); //Connect TX and RX with a wire and run this sketch //Remove A0, A1 resistors which set the I2C address //Remove SCL pull up resistors if you are using Duemilanove //Pin 6 should be connected to CS of the module. //#define baudrate 57600 //#define baudrate 115200 #define baudrate 230400 //#define baudrate 460800 //#define baudrate 921600 void setup() { Serial.begin(115200); Serial.println("Start testing"); // UART to Serial Bridge Initialization spiuart.begin(baudrate); //baudrate setting Serial.println("BAUDRATE SET"); if (spiuart.ping()!=1) { Serial.println("Device not found"); while(1); } else { Serial.println("Device found"); } Serial.print("start serial communication. baudrate = "); Serial.println(baudrate); } void loop() { static char buffer[64] = {0}; static int index = 0; if (spiuart.available() > 0) { // read the incoming byte: char c = spiuart.read(); #if 0 Serial.print("c="); if (c < 0x20) { Serial.print(" "); } else { Serial.print(c); } Serial.print(" 0x"); Serial.println(c,HEX); #endif if (c == 0x0d) { } else if (c == 0x0a) { Serial.print("["); Serial.print(buffer); Serial.println("]"); index = 0; } else { buffer[index++] = c; buffer[index] = 0; } } } |