Go Down

Topic: SPI Primer (Read 2156 times) previous topic - next topic

Ronduino

I need to get my feet pointed correctly with some good examples of using the SPI protocol with Arduino. I was told to include the SPI library into the sketch, though the examples I find do not include the SPI library...What is the reason for this? :-? :-?

Ronduino

Here is a link to the data sheet for the 4 digit display that I am trying to link via SPI:

http://www.sparkfun.com/datasheets/Components/LED/SFE-0012-DS-7segmentSerial-v3.pdf

This display has an ATMega integrated on the backside...it seems that really I'm trying to communicate from one ATMega to another. I am a bit new to the Arduino platform, and completely new to SPI. My current goal is to have the display show a time...say 10:30 . I'm thinking I need some good examples of SPI projects, if not direct advice for using this display. Thank you for your reply.
:o

Grumpy_Mike

Quote
What is the reason for this


It is probably because the SPI library doesn't do very much when you look at the code in it.
This is some code I wrote for addressing two MCP23S17 chips through SPI for a CNC project to control stepping motors:-

Code: [Select]
// two MCP23S17 SPI port expander chips

setup(){
// initilise SPI expanders
       // Set up ICON register it defaults to address 0xA on reset:
       expanderW(MOTOR_WRITE, 0x0A, BANK | SEQOP | HAEN); // this sets both / all expanders to use address pins
       expanderW(LIMIT_WRITE, 0x0A, BANK | SEQOP | HAEN); // this sets both / all expanders to use address pins
       expanderW(LIMIT_WRITE,IODIRA, 0xff);      // Data direction register A all inputs
       expanderW(LIMIT_WRITE,IODIRB, 0xff);      // Data direction register B all inputs
       expanderW(LIMIT_WRITE,IPOLA, 0xff);       // Input polarity read an earth (press) as a one
       expanderW(LIMIT_WRITE,IPOLB, 0xff);       // Input polarity read an earth (press) as a one
       expanderW(LIMIT_WRITE,INTCONB, 0x00);     // Notify on change
       expanderW(LIMIT_WRITE,INTCONB, 0x00);     // Notify on change
       expanderW(LIMIT_WRITE,GPINTENA, 0xff);    // enable notifacation on pins
       expanderW(LIMIT_WRITE,GPINTENB, 0xff);    // enable notifacation on pins
       expanderW(MOTOR_WRITE,IODIRA, 0x00);      // Data direction register A all outputs
       expanderW(MOTOR_WRITE,IODIRB, 0x00);      // Data direction register B all outputs
       expanderW(MOTOR_WRITE, GPIOB, 0x00);      // disable motors, set dir to 0, set step to 0

}

byte expanderR(byte com,byte add)
{
 byte value;
 digitalWrite(SS_PIN, LOW);
 Spi.transfer(com);  // address read
 Spi.transfer(add);   //  register address
 value = Spi.transfer(0x0);   //  dummy data for read
 digitalWrite(SS_PIN, HIGH);
 return value;
}

byte expanderW(byte com, byte add, byte dat) // expander read
{
 digitalWrite(SS_PIN, LOW);
 Spi.transfer(com);  // address write
 Spi.transfer(add);   //  register address
 Spi.transfer(dat);   //  register data
 digitalWrite(SS_PIN, HIGH);
}

Go Up