SC16IS750 SPI connection and receiving no output
hello,
i want send data via spi sc160is750 , data via uart.
this 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 1k resitor.
tx - ftdi rx
gnd - ftdi gnd arduino
hardware: http://www.sparkfun.com/products/9981
i having trouble looking @ data in output of the breakout board...nothing coming out. here code:
i want send data via spi sc160is750 , data via uart.
this 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 1k resitor.
tx - ftdi rx
gnd - ftdi gnd arduino
hardware: http://www.sparkfun.com/products/9981
i having trouble looking @ data in output of the breakout board...nothing coming out. here code:
code: [select]
#include <spi.h>
const int cs=10; //chip select
char data;
// sc16is750 register definitions
// todo: don't bit shift these here, in read/write register routines
//note:in spi mode, sda / vss pin not connected 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);
spi_uart_init();
spi_uart_init();
spi_uart_init();
if (spi_uart_init())
{
serial.println("spi_uart initialized successfully!");
}
else
{
serial.println("could not initialize!!!");
while(1);
}
/*spi_uart_init();
spi_uart_init();
spi_uart_init();
spi_uart_init();
spi_uart_init(); //initialized twice or more, otherwise initialization not successful
*/
}
void select(void)
{
digitalwrite(cs,low);
}
void deselect(void)
{
digitalwrite(cs,high);
}
char spi_transfer(volatile char data)
{
spdr = data; // start transmission
while (!(spsr & (1<<spif))) // wait end of transmission
{
};
return spdr; // return received byte
}
long int spi_write(char* srcptr, long int length)
// write string sc16is750
{
for(long int = 0; < length; i++)
{
spi_transfer(srcptr[i]);
}
return length;
}
char spi_uart_readbyte(char address)
// read sc16is750 register @ <address>
{
char data;
address = (address | 0x80);
select();
spi_transfer(address);
data = spi_transfer(0xff);
deselect();
return data;
}
/*void spi_uart_writearray(char *data, long int numbytes)
// write array sc16is750 thr
{
long int length;
select();
length = spi_write(&tx_fifo_address,1);
while(numbytes > 16)
{
length = spi_write(data,16);
numbytes -= 16;
data += 16;
}
length = spi_write(data,numbytes);
deselect();
}*/
void spi_uart_writebyte(char address, char data)
// write <data> sc16is750 register @ <address>
{
long int length;
char senddata[2];
senddata[0] = address;
senddata[1] = data;
select();
length = spi_write(senddata, 2);
deselect();
}
void loop() {
//read
digitalwrite(cs, low);
spi.transfer(rhr|0x80);
data=spi.transfer(0xff);
digitalwrite(cs, high);
//delay(1000);
serial.println(data);
//write
digitalwrite(cs, low);
spi.transfer(thr);
spi.transfer(data);
digitalwrite(cs, high);
delay(1000);
}
//=====================================
int spi_uart_init(){
pinmode(cs,output); // chip select
// start 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);
// perform read/write test check if uart working
//write
digitalwrite(cs, low);
spi.transfer(thr);
spi.transfer('h');
digitalwrite(cs, high);
delay(1000);
//read
digitalwrite(cs, low);
spi.transfer(rhr|0x80);
data=spi.transfer(0xff);
digitalwrite(cs, high);
//delay(1000);
serial.print("data received: ");
serial.println(data);
if(data == 'h'){
return 1;
}
else {
return 0;
}
}
code: [select]
spi_uart_init();
spi_uart_init();
spi_uart_init();isn't once enough?
isn't once enough?
isn't once enough?
links hardware?
quote
i want send data via spi sc160is750 , data via uart.
why?
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > SC16IS750 SPI connection and receiving no output
arduino
Comments
Post a Comment