Hello,
I want to send data via the SPI to the SC160IS750 and get the data back via UART.
This is my current connection:
I2C/SPI - GND
A0/CS - PIN 10
A1/SI - MISO PIN 12
NC/SO - MOSI PIN 11
SCL-SCK - PIN 13
SDA - VSS - GND
VIN - 3.3v ARDUINO
IRQ - Vdd with 1k resitor.
TX - FTDI RX
GND - FTDI GND with Arduino
I am currently having trouble looking at the data in the output of the the breakout board…nothing is coming out. Here is my code:
#include <SPI.h>
const int cs=10; //chip select
unsigned char data;
// SC16IS750 Register definitions
// TODO: Don't bit shift these here, do it in the read/write register routines
//NOTE:In the spi mode, SDA / VSS pin is not connected to the power
#define THR 0x00 << 3
#define RHR 0x00 << 3
#define IER 0x01 << 3
#define FCR 0x02 << 3
#define IIR 0x02 << 3
#define LCR 0x03 << 3
#define MCR 0x04 << 3
#define LSR 0x05 << 3
#define MSR 0x06 << 3
#define SPR 0x07 << 3
#define TXLVL 0x08 << 3
#define RXLVL 0x09 << 3
#define DLAB 0x80 << 3
#define IODIR 0x0A << 3
#define IOSTATE 0x0B << 3
#define IOINTMSK 0x0C << 3
#define IOCTRL 0x0E << 3
#define EFCR 0x0F << 3
#define DLL 0x00 << 3
#define DLM 0x01 << 3
#define EFR 0x02 << 3
#define XON1 0x04 << 3
#define XON2 0x05 << 3
#define XOFF1 0x06 << 3
#define XOFF2 0x07 << 3
void setup() {
SPI.begin();
Serial.begin(9600);
RTC_init();
RTC_init();
RTC_init();
RTC_init();
RTC_init();
RTC_init(); //Initialized twice or more, otherwise the initialization is not successful
}
void loop() {
digitalWrite(cs, LOW); //read
SPI.transfer(RHR|0x80);
data=SPI.transfer(0xff);
digitalWrite(cs, HIGH);
//delay(1000);
Serial.println(data);
digitalWrite(cs, LOW); //write
SPI.transfer(THR);
SPI.transfer(data);
digitalWrite(cs, HIGH);
delay(1000);
}
//=====================================
int RTC_init(){
pinMode(cs,OUTPUT); // chip select
// start the SPI library:
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
//set control register
digitalWrite(cs, LOW);
SPI.transfer(LCR);
SPI.transfer(0x80);
digitalWrite(cs, HIGH);
digitalWrite(cs, LOW);
SPI.transfer(DLL);
SPI.transfer(0x60);
digitalWrite(cs, HIGH);
digitalWrite(cs, LOW);
SPI.transfer(DLM);
SPI.transfer(0x00);
digitalWrite(cs, HIGH);
digitalWrite(cs, LOW);
SPI.transfer(LCR);
SPI.transfer(0xbf);
digitalWrite(cs, HIGH);
digitalWrite(cs, LOW);
SPI.transfer(EFR);
SPI.transfer(0xd0);
digitalWrite(cs, HIGH);
digitalWrite(cs, LOW);
SPI.transfer(LCR);
SPI.transfer(0x03);
digitalWrite(cs, HIGH);
digitalWrite(cs, LOW);
SPI.transfer(FCR);
SPI.transfer(0x06);
digitalWrite(cs, HIGH);
digitalWrite(cs, LOW);
SPI.transfer(FCR);
SPI.transfer(0x01);
digitalWrite(cs, HIGH);
}