├── SPI_Bridge.zip ├── examples └── SELFTEST │ └── SELFTEST.ino ├── README.txt ├── SC18IS602.h └── SC18IS602.cpp /SPI_Bridge.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SandboxElectronics/SPI_Bridge/master/SPI_Bridge.zip -------------------------------------------------------------------------------- /examples/SELFTEST/SELFTEST.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | //Connect the MOSI and MISO with a wire and run this sketch. 5 | SC18IS602 i2cspi=SC18IS602(SC18IS602_ADDRESS_000); 6 | void setup() 7 | { 8 | Serial.begin(9600); 9 | i2cspi.begin(0); 10 | Serial.println("Start SPI communication"); 11 | } 12 | 13 | void loop() 14 | { 15 | 16 | //Serial.println(i2cspi.transfer(0xFF)); 17 | if ( i2cspi.transfer(0x55) != 0x55) { 18 | Serial.println("Communication Error"); 19 | while(1); 20 | } 21 | if ( i2cspi.transfer(0xAA) != 0xAA) { 22 | Serial.println("Communication Error"); 23 | while(1); 24 | } 25 | 26 | Serial.println("Communication is good"); 27 | delay(300); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Arduino Library for Sandbox Electronics SC18IS602 I2C to SPI Bridge Module [MOD-000021] 2 | ======================================================================================= 3 | 4 | This module is available at http://sandboxelectronics.com/?product=sc18is602-i2c-to-spi-bridge-module 5 | 6 | Installation Instruction (For Arduino IDE version 1.0.5 and above): 7 | 8 | 1. Download the library as an Arduino IDE compatible zip file at https://github.com/SandboxElectronics/SPI_Bridge/blob/master/SPI_Bridge.zip?raw=true. (Do not unzip it. leave it as is) 9 | 10 | 2. In the Arduino IDE, select Sketch -> Import Library -> Add Library 11 | 12 | 3. Navigate to the zip file that was just downloaded - SPI_Bridge.zip, and Click Open. 13 | 14 | 4. Return to the Sketch -> Import Library menu. You should now see the library at the bottom of the drop-down menu. It is ready to be used in your sketch. 15 | 16 | The installed library should be under: 17 | - My Documents\Arduino\libraries\ (on Windows) 18 | - Documents/Arduino/libraries/ (on Mac or Linux) 19 | 20 | Note: the above instruction is for automatic installation of 3rd party libraries that is supported starting at Arduino IDE 1.0.5. For users running earlier versions, manual installation is required. For manual installation instruction, please visit http://arduino.cc/en/Guide/Libraries. Please remember to close all opened Arduino IDE windows and restart the Arduino IDE if manual installation was used. Please make sure the new library appears in the Sketch -> Import Library menu item of the software. 21 | -------------------------------------------------------------------------------- /SC18IS602.h: -------------------------------------------------------------------------------- 1 | /* 2 | Description: 3 | This is a example code for Sandbox Electronics' I2C to SPI bridge module. 4 | You can get one of those products on 5 | http://sandboxelectronics.com 6 | 7 | Version: 8 | V0.1 9 | 10 | Release Date: 11 | 2014-02-16 12 | 13 | Author: 14 | Tiequan Shao info@sandboxelectronics.com 15 | 16 | Lisence: 17 | CC BY-NC-SA 3.0 18 | 19 | Please keep the above information when you use this code in your project. 20 | */ 21 | 22 | 23 | #ifndef _SC18IS602_H_ 24 | #define _SC18IS602_H_ 25 | 26 | #if ARDUINO >= 100 27 | #include "Arduino.h" 28 | #else 29 | #include "WProgram.h" 30 | #endif 31 | 32 | #include 33 | //Device Address 34 | 35 | #define SC18IS602_ADDRESS_000 (0X50) 36 | #define SC18IS602_ADDRESS_001 (0X52) 37 | #define SC18IS602_ADDRESS_010 (0X54) 38 | #define SC18IS602_ADDRESS_011 (0X56) 39 | #define SC18IS602_ADDRESS_100 (0X58) 40 | #define SC18IS602_ADDRESS_101 (0X5A) 41 | #define SC18IS602_ADDRESS_110 (0X5C) 42 | #define SC18IS602_ADDRESS_111 (0X5E) 43 | 44 | //Clock Divider 45 | #define SC18IS602_CLOCK_1843K (0X00) 46 | #define SC18IS602_CLOCK_461K (0X01) 47 | #define SC18IS602_CLOCK_115K (0X02) 48 | #define SC18IS602_CLOCK_58K (0X03) 49 | 50 | #define SC18IS602_SPI_MODE0 (0x00) 51 | #define SC18IS602_SPI_MODE1 (0x01) 52 | #define SC18IS602_SPI_MODE2 (0x02) 53 | #define SC18IS602_SPI_MODE3 (0x03) 54 | 55 | #define SC18IS602_SS_0 (0X00) 56 | #define SC18IS602_SS_1 (0X01) 57 | #define SC18IS602_SS_2 (0X02) 58 | #define SC18IS602_SS_3 (0X03) 59 | 60 | 61 | 62 | class SC18IS602 63 | { 64 | public: 65 | SC18IS602(uint8_t addr = SC18IS602_ADDRESS_000); 66 | void begin(); 67 | void begin(uint8_t ss_pin); 68 | void end(); 69 | void setBitOrder(uint8_t order); //LSBFIRST MSBFIRST 70 | void setClockDivider(uint8_t divider); 71 | void setDataMode(uint8_t mode); 72 | uint8_t transfer(uint8_t value); 73 | uint8_t transfer(uint8_t* buffer, uint8_t length); 74 | void pinMode(uint8_t pin, uint8_t io); 75 | void digitalWrite(uint8_t pin, uint8_t value); 76 | uint8_t digitalRead(uint8_t pin); 77 | void InterruptClear(void); 78 | 79 | private: 80 | uint8_t device_address; 81 | uint8_t ss_pin; 82 | uint8_t reg_f0_config; //configuration register 0xF0 83 | uint8_t reg_f4_gpio_w; //gpio write register 84 | uint8_t reg_f5_gpio_r; //gpio read register 85 | uint8_t reg_f6_gpio_e; //gpio enable register 86 | uint8_t reg_f7_gpio_d; //gpio direction 87 | void ResetDevice(void); 88 | void GPIOEnable(uint8_t pin); 89 | void SSEnable(uint8_t pin); 90 | 91 | 92 | uint8_t ReadBytes(uint8_t* buffer, uint8_t length); 93 | uint8_t ReadByte(void); 94 | void WriteBytes(uint8_t* buffer, uint8_t length); 95 | void WriteRegister(uint8_t reg_addr, uint8_t val); 96 | 97 | 98 | 99 | }; 100 | 101 | #endif 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /SC18IS602.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Description: 3 | This is a example code for Sandbox Electronics' I2C/SPI to UART bridge module. 4 | You can get one of those products on 5 | http://sandboxelectronics.com 6 | 7 | Version: 8 | V0.1 9 | 10 | Release Date: 11 | 2014-02-16 12 | 13 | Author: 14 | Tiequan Shao info@sandboxelectronics.com 15 | 16 | Lisence: 17 | CC BY-NC-SA 3.0 18 | 19 | Please keep the above information when you use this code in your project. 20 | */ 21 | 22 | 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #ifdef __AVR__ 29 | #define WIRE Wire 30 | #else // Arduino Due 31 | #define WIRE Wire1 32 | #endif 33 | 34 | 35 | SC18IS602::SC18IS602(uint8_t addr) 36 | { 37 | device_address = (addr>>1); 38 | } 39 | 40 | 41 | void SC18IS602::ResetDevice(void) 42 | { 43 | 44 | reg_f0_config = 0x00; //configuration register 0xF0 45 | reg_f4_gpio_w = 0x00; //gpio write register 46 | reg_f5_gpio_r = 0x0F; //gpio read register 47 | reg_f6_gpio_e = 0x00; //gpio enable register 48 | reg_f7_gpio_d = 0xAA; //gpio direction 49 | WriteRegister(0xf0,reg_f0_config); 50 | WriteRegister(0xf4,reg_f4_gpio_w); 51 | // WriteRegister(reg_f5_gpio_r,0x0F); 52 | WriteRegister(0xf6,reg_f6_gpio_e); 53 | WriteRegister(0xf7,reg_f7_gpio_d); 54 | 55 | pinMode(0,INPUT); 56 | pinMode(1,INPUT); 57 | pinMode(2,INPUT); 58 | pinMode(3,INPUT); 59 | GPIOEnable(0); 60 | GPIOEnable(1); 61 | GPIOEnable(2); 62 | GPIOEnable(3); 63 | 64 | } 65 | 66 | void SC18IS602::GPIOEnable(uint8_t pin) 67 | { 68 | reg_f6_gpio_e |= ( 0x01<