Jump to content
43oh

Stellaris LaunchPad SPI.begin(slaveSelectPin)


Recommended Posts

I'm trying to combine some Energia libraries for the ADS1118 ADC and the SPI serial LCD included on the ADS1118 Booster Pack.  Using simple digitalWrite() calls, I'm able to write to the LCD, but I'm trying to switch to using the Energia SPI library.  The documentation for SPI.begin() says I can set a slave select pin; however, the compiler rejects a call to SPI.begin(LCD_CS) because there is no SPI.begin(int slaveSelectPin) defined.  

 

With the following code, the default pin 2 slave select appears to be used, because it happens to be connected to the buzzer on the ADS1118 Booster Pack, and I can hear it.  

 

Judging from the description, Energia commit 5c4dab5 seems to be aimed at fixing this, but it still doesn't work as expected.  

// Stellaris LaunchPad with ADS1118 Booster Pack

#include <SPI.h>

int LCD_RS = 12;                      // Register Select
int LCD_CS = 13;                      // LCD chip select

int ADC_CS = 8;                       // ADS1118 chip select
int SI = 15;                          // Slave Serial data Input
int SO = 14;                          // Slave Serial data Output
int SCL = 7;                          // Serial data CLock

int BUZZER = 2;                       // ADS1118 buzzer pin

void setup()
{
  Serial.begin(9600);
  Serial.println("# -+-+- RESET -+-+-");
  
  // initialize the LCD
  pinMode(LCD_RS, OUTPUT); 
  pinMode(SI, OUTPUT); 
  pinMode(SO, INPUT); 
  pinMode(SCL, OUTPUT);
  pinMode(LCD_CS, OUTPUT);
  delay(10);
  writecom(0x30);                     // wake up
  writecom(0x30);                     // wake up
  writecom(0x30);                     // wake up
  writecom(0x39);                     // function set
  writecom(0x14);                     // internal osc frequency
  writecom(0x70);                     // contrast  
  writecom(0x56);                     // power control
  writecom(0x6D);                     // follower control
  delay(10);
  writecom(0x0C);                     // display on
  writecom(0x01);                     // clear
  delay(5);  
  writecom(0x06);                     // entry mode
  delay(10);
}

void loop()
{
  Serial.print("#  loop ");
  lcdClear();
  lcdPrint("Hello world!");
  sleep(1000);
}

void lcdClear() {
  writecom(0x01);
  delay(5);
}

void lcdMoveTo(unsigned int x) {
  writecom(0x80 + (x & 0x7f));
  delay(5);
}

void lcdPrint(char *s) {
  while(*s != 0) {
    lcdPrintChar(*s++);
  }
}

void lcdPrintChar(char c) {
  writedata(c);
  delay(1);
}

void writecom(int d) {
  SPI.begin();                            // SPI.begin(LCD_CS) does not work
  SPI.setClockDivider(SPI_CLOCK_DIV128);
  digitalWrite(LCD_CS, LOW);
  digitalWrite(LCD_RS, LOW);              // LOW = command
  SPI.transfer(d);
  digitalWrite(LCD_CS, HIGH);
  SPI.end();                              // SPI.end(LCD_CS) does not work
}

void writedata(int d) {
  SPI.begin();                            // SPI.begin(LCD_CS) does not work
  SPI.setClockDivider(SPI_CLOCK_DIV128);
  digitalWrite(LCD_CS, LOW);
  digitalWrite(LCD_RS, HIGH);             // HIGH = data
  SPI.transfer(d);
  digitalWrite(LCD_CS, HIGH);
  SPI.end();                              // SPI.end(LCD_CS) does not work
}
Link to post
Share on other sites

SPI Slave isn't implemented.

 

See ticket #378 Implement SPI Slave on Energia.

 

I'm not attempting to use the Stellaris as an SPI slave.  Do you mean that the Energia documentation for SPI.begin(slaveSelectPin) intends for the slaveSelectPin to be an input for the unimplemented case of the Stellaris as as SPI slave?  I understood it to mean that slaveSelectPin is the Stellaris pin that is connected to chip select on the SPI slave device, for example, chip select on the ADS1118.  

Link to post
Share on other sites

 

I've never used SPI.begin(slaveSelectPin).
 
Instead, I'm using 
 
digitalWrite(slaveSelectPin, LOW);
// ...
digitalWrite(slaveSelectPin, HIGH);

 

 

I am doing the same (see my writecom() for example).  The problem is that the LaunchPad pin 2 is still being set for output and toggled by SPI.transfer().  This causes the buzzer to buzz every time an SPI transfer is attempted.  

 

Also, the documentation should be updated to remove SPI.begin(pin), since that no longer compiles.  

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...