Pages: [1]   Go Down
Author Topic: Arduino Serial I/O expansion, Serial Peripheral Interface (SPI) using MPC23S08  (Read 1088 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello!

I was searching for hours for a working sample of the SPI version of the MPC23x08. I run into troubles with the configuration of the SPI Interface (Phase and Clock). For all here's a small running sample:


#define CONTROL_BYPE 0x40 // 0100 0000
//                                |||+-- R/W 0 == write
//                                ||+--- A0
//                                |+---- A1

#define chipSelectPin 10
#define BITORDER MSBFIRST
#define DATAMODE SPI_MODE3   // testes with  Mode  2 and 3

void setup() {

  // setup the protocol

  SPI.setClockDivider(SPI_CLOCK_DIV2);   // testes also with higher values mit 2
  SPI.setBitOrder(BITORDER) ;
  SPI.setDataMode(DATAMODE) ;

  // prepare for output

  SPI.begin();
  pinMode(chipSelectPin, OUTPUT);
  digitalWrite(chipSelectPin, HIGH);   

  digitalWrite(chipSelectPin, LOW); 
  SPI.transfer(0x40);
  SPI.transfer(0x00);                   // select the IODIR register
  SPI.transfer(0xff);                   // set register value-all high, sets all pins as outputs on MCP23008
  digitalWrite(chipSelectPin, HIGH);   
  SPI.end();
}

// flash all connected LED

void loop() {

  SPI.begin();
  digitalWrite(chipSelectPin, LOW);   
  SPI.transfer(0x40);
  SPI.transfer(0x09);                   // select the GPIO register
  SPI.transfer(0xff);                   // set register value-all high
  digitalWrite(chipSelectPin, HIGH); 
  SPI.end();                             // stop talking to the device
  delay(500);                           // wait for 1/2 a second

  SPI.begin();
  digitalWrite(chipSelectPin, LOW); 
  SPI.transfer(0x40);
  SPI.transfer(0x09);                   // select the GPIO register
  SPI.transfer(0x00);                   // set register value-all low
  digitalWrite(chipSelectPin, HIGH); 
  SPI.end();                             // stop talking to the device
  delay(500);            // wait for 1/2 a second
}


Hope this will speed up the work for others.

And don't forget Arduino MSIO goes to Chip MSIN and Arduino MSIN to MSIO   smiley-confuse This was my bigges problem!
Logged

Pages: [1]   Go Up
Jump to: