Go Down

Topic: Serial over usb & SPI output (Read 1 time) previous topic - next topic


Hi there

Is it possible to input serial to the arduino uno, over usb, then convert this to SPI so an SPI enabled device can function with it?
Any help would be appreciated.



Did you try something simple like this:

Code: [Select]

// the sensor communicates using SPI, so include the library:
#include <SPI.h>

// pins used for the connection with the sensor
// the other you need are controlled by the SPI library):
const int chipSelectPin = 7;

void setup() {

  pinMode(chipSelectPin, OUTPUT);

void loop() {
  uint8_t MOSIbyte, MISObyte;
  if (Serial.available() > 0)
    // take the chip select low to select:
    digitalWrite(chipSelectPin, LOW);

    // Loop till out of input so we don't de-select after every byte
    while (Serial.available() > 0)
      MOSIbyte = Serial.read();

      MISObyte = SPI.transfer(MOSIbyte);

    // take the chip select high to de-select:
    digitalWrite(chipSelectPin, HIGH);
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp



I have tried your code, but nothing can be seen on the serial monitor!
I want to take in data through SPI ports and see that on serial monitor, I am using ADIS16210 sensor and Arduino UNO!
Please let em know your suggestions!!!



You should start by reading the device's datasheet:


You have to send commands to the device to read the values.  The values are in binary.  If you want something human-readable you will need to interpret the data some before printing the values to your serial monitor.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


Hello John,

I have tried many things but couldn't get any data from the sensor and display it on the serial monitor. Need your serious guidance to resolve this issue asap. I am using the code below.

Code: [Select]
//Add the SPI library so we can communicate with the ADIS16210 sensor
#include <SPI.h>

//Assign the Chip Select signal to pin 10.
int CS=10;

//This is a list of some of the registers available on the ADIS16210.
//To learn more about these and the rest of the registers on the ADIS16210, read the datasheet!

#define BIT4         0x0010
#define FLASH_CNT 0x00 // Diagnostics, flash write counter (16-bit binary)
#define SUPPLY_OUT 0x02 // Output, power supply
#define XACCL_OUT 0x04 // Output, x-axis acceleration
#define YACCL_OUT 0x06 // Output, y-axis acceleration
#define ZACCL_OUT 0x08 // Output, z-axis acceleration
#define TEMP_OUT 0x0A // Output, internal temperature
#define XINCL_OUT 0x0C // Output, ±180° x-axis inclination
#define YINCL_OUT 0x0E // Output, ±180° y-axis inclination
#define ZINCL_OUT 0x10 // Output, ±180° z-axis inclination
#define XACCL_NULL 0x12 // Calibration, x-axis acceleration offset null
#define YACCL_NULL 0x14 // Calibration, y-axis acceleration offset null
#define ZACCL_NULL 0x16 // Calibration, z-axis acceleration offset null
#define ALM_MAG_X 0x20 // Alarm, x-axis amplitude threshold
#define ALM_MAG_Y 0x22 // Alarm, y-axis amplitude threshold
#define ALM_MAG_Z 0x24 // Alarm, z-axis amplitude threshold
#define ALM_MAG_S 0x26 // Alarm, system alarm threshold
#define ALM_SMPL_X 0x28 // Alarm, x-axis sample period
#define ALM_SMPL_Y 0x2A // Alarm, y-axis sample period
#define ALM_SMPL_Z 0x2C // Alarm, z-axis sample period
#define ALM_CTRL 0x2E // Operation, alarm control
#define GPIO_CTRL 0x32 // Operation, general I/O configuration and data
#define MSC_CTRL 0x34 // Operation, orientation mode
#define DIO_CTRL 0x36 // Operation, digital I/O configuration and data
#define AVG_CNT 0x38 // Operation, decimation filter configuration
#define SLP_CNT 0x3A // Operation, sleep count
#define DIAG_STAT 0x3C // Diagnostics, system status register
#define GLOB_CMD 0x3E // Operation, system command register
#define LOT_ID1 0x52 // Lot identification, Code 1
#define LOT_ID2 0x54 // Lot identification, Code 2
#define PROD_ID 0x56 // Production identification number
#define SERIAL_NUM 0x58 // Serial Number

void setup()

  //Configure the SPI connection for the ADIS16210.
  //Initiate an SPI communication instance.

  //Create a serial connection to display the data on the terminal.
  Serial.begin(9600); // send info to serial port
  Serial.println("Start ADIS16210 Accelorometer Sensor Demo....");
// initialize ADIS16210
//    sensor_init();
// read sample from device and print to uart

void sensor_init(void)

  // set average count / sample rate to 1Hz (512Hz/(2^9)

        // data ready enabled on DIO1, busy indicator enabled on DIO2


void loop(void)
short x_accl, y_accl, z_accl, serialID;

// read accelaration
x_accl = read_reg(XACCL_OUT);
y_accl = read_reg(YACCL_OUT);
z_accl = read_reg(ZACCL_OUT);



void command(unsigned char val)
// send command


void write_reg(unsigned char address, unsigned char value)
digitalWrite(CS, LOW); // Enable sensor /CS           // lower !CS pin
SPI.transfer(0x80 | 0x04);
digitalWrite(CS, HIGH); // disable sensor /CS              // raise !CS pin

delay(45);   // stall time is 40us for ADIS16210


void write_reg_int(unsigned char address, unsigned short data)


short int read_reg(unsigned char address)
short int data;
short int hi_byte, lo_byte;

digitalWrite(CS, LOW);           // lower !CS pin

// send address (1st two bytes)

delay(45);   // stall time is 40us on adis16210 with normal mode

// send dummy bytes for data
hi_byte = SPI.transfer(0x00);
lo_byte = SPI.transfer(0x00);

digitalWrite(CS, HIGH);             // raise !CS pin

data = (hi_byte << 8) | lo_byte;

delay(45);   // stall time is 40us on adis16210 with normal mode

// return data read from device at 'address'
//return data;

Go Up