jp430bb 8 Posted June 30, 2015 Share Posted June 30, 2015 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 } Quote Link to post Share on other sites
Rei Vilo 695 Posted June 30, 2015 Share Posted June 30, 2015 SPI Slave isn't implemented. See ticket #378 Implement SPI Slave on Energia. Quote Link to post Share on other sites
jp430bb 8 Posted June 30, 2015 Author Share Posted June 30, 2015 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. Quote Link to post Share on other sites
Rei Vilo 695 Posted June 30, 2015 Share Posted June 30, 2015 I've never used SPI.begin(slaveSelectPin). Instead, I'm using digitalWrite(slaveSelectPin, LOW); // ... digitalWrite(slaveSelectPin, HIGH); Quote Link to post Share on other sites
jp430bb 8 Posted June 30, 2015 Author Share Posted June 30, 2015 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. Quote Link to post Share on other sites
jp430bb 8 Posted July 2, 2015 Author Share Posted July 2, 2015 I've added a pinMode(2, INPUT_PULLUP) after the SPI stuff in setup() to stop the buzzer from sounding. Except for what looks like a conflict with the JTAG pins, I've got SPI writing to the ADS1118 Booster Pack LCD OK now. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.