Jump to content
43oh

SOLVED: SPI on C2000 launchpad


Recommended Posts

Don't give up!!! Take heart, I believe I've found your issue. The chip select for the LCD is routed to ADCINA4 (which can be used as a GPIO). You need to configure this pin to be a GPIO...perhaps something like this:

EALLOW;
GpioCtrlRegs.AIOMUX1.bit.AIO4 = 0;
GpioCtrlRegs.AIODIR.bit.AIO4 = 1;
GpioDataRegs.AIODAT.bit.AIO4 = 1;
EDIS;

 

and then when you transmit and recieve you need to drive this pin low. Perhaps you could change LCDSPI to something like this:

void LCDSPI(uint16_t command, uint16_t data)
{
char first = (command << 7) | (data >> 1);
char second = (data << 7);

GpioDataRegs.AIODAT.bit.AIO4 = 0;
SPI_write(mySpi, command<<8);
SPI_write(mySpi, data<<8 );
GpioDataRegs.AIODAT.bit.AIO4 = 1;
}

 

Give that a try...I bet we see this LCD working before 5pm today.

Link to post
Share on other sites
  • Replies 46
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Hey CorB, looks like we have been working on the same project. Ive also written some code (needs tidying still but will post when Im happy) to drive these LCDs. As Ive been using mine for the $4.30

CorB,   I solved the issues with the original example. It turns out the order in which the FIFO register bit fields are configured is important. To the best of my knowledge this isn't documented i

Replace your common directory with this Import the driverlib project from this directory Build the driverlib project Rebuild the SPI example with the code posted above The example should wor

Posted Images

Added the suggest code and changed the routine (also corrected the mistake as command << 8 should have been first <<8) ... but all with 0 results. I am btw close to 11 pm (I live in the Netherlands).

Edited by CorB
Link to post
Share on other sites

Trey,

 

Going through the code you suggested, just a few remarks and questions:

 

I guess the code below sets up the pin called ADCINA4 (see Spruhh2.pdf documentation) for output ? One thing I find rather complicating is that in the documentation for the c2000 launchpad this pin is called ADCINA4 (= P1.4 position on msp430 launchpad) but in the code I am currently using the GPIO is defined in a file F2802x_Gpio.h and there is no sign of ADCINA4. It seems we need to use the AIO4 bit instead.

 

EALLOW;

 

1) GpioCtrlRegs.AIOMUX1.bit.AIO4 = 0;

2) GpioCtrlRegs.AIODIR.bit.AIO4 = 1;

3) GpioDataRegs.AIODAT.bit.AIO4 = 1;

EDIS;

1) sets the MUX for this particular pin to functionality 0 ? According to spruhh2 there is no other functionality on this pin BTW.

2) sets the dir to output ?

3) raises the pin ?

 

This pin is the Chip_select pin for the LCD so it should indeed be lowered (high=inactive) before sending data to the LCD.

 

EDIT:

Checked the original source and this line is interesting (ive added the comments just now)

 

char first = (command << 7) | (data >> 1); // first bit = command (0x01 or 0x00), next 7 bits are data MSB->LSB

char second = (data << 7); // 1st bit is data LSB

 

In conclusion in the original code we are sending 2 8bits packs in sequenst that are in fact a 9 bit datastream instead of an 8 bit datastream it seems. So if I just setup for 9 bit datatransfer and fill (left-justified) a uint16_t variable with this data ... we could have succes ?

Edited by CorB
Link to post
Share on other sites

More work tested, the new LCDSPI routine is:

 


void LCDSPI(uint16_t command, uint16_t data)
{
//char first = (command << 7) | (data >> 1);  // first bit = command, next 7 bits are data MSB->LSB
//char second = (data << 7); // 1st bit is data LSB

uint16_t spidata;
spidata = command<<15;
spidata = spidata | data <<7;

GpioDataRegs.AIODAT.bit.AIO4 = 0;
SPI_write(mySpi, spidata);
GpioDataRegs.AIODAT.bit.AIO4 = 1;
}

 

Ive checked using the debugger that the spidata is correct, first bit corresponds to the command and the next 8 bits are the dataword and everything is left justified in a uint16_t variable.

 

Ive set the SPI for 9 bits using:

 

SPI_setCharLength(mySpi, SPI_CharLength_9_Bits);

 

 

decreased the speed of the clock using:

 

 

PLL_setup(myPll, PLL_Multiplier_1, PLL_DivideSelect_ClkIn_by_4);

 

which should lower the clock to 10Mhz*1/4 = 2.5Mhz ?

 

And the result is still no sign of any pixel turning black on the LCD ...

Link to post
Share on other sites

I just checked the info for the ST7579 controller, it seems it has a speed constraint for the Clockpulse it should be at least 120ns long, see http://lars.roland.bz/test/ST7579.pdf page 48.

 

The code for the F2802xSPI currently allows 2 use two predefined baudrate settings (speed estimated for a 12.5Mhz clock) 500kbaud and 1Mbaud. As I have turned the systemclock down to 2.5Mhz (I hope ...) my current setting of 500kbaud should be equal to 100 kbaud. So each serialclockpulse is 1/100000 of a second ... and thats more than 120ns ... so also that seems to be not the real issue.

Link to post
Share on other sites

Next test was using the so-called loopback mode. Reading the docs ( http://www.ti.com/li...1b/sprug71b.pdf page 25) shows that it can be used to test SPI functionality ... I used the default code from controlsuite and I got an error spit back at me from the software suggesting that SPI data did not get send. I will now remove the LCD and see again.

 

EDIT: Tried again using completely unmodified code Example_F2802xSpi_FFDLB_int (from controlsuite examples) with this date/versionstamp

 

//#############################################################################

// $TI Release: f2802x Support Library v200 $

// $Release Date: Tue Jul 24 10:01:39 CDT 2012 $

//#############################################################################

 

Running this code without the LCD attached I do get an error that the data read from the SPI (loopback) isnt the same as the data written by the SPI. This makes me feel something on the launchpad might be wrong ... did anybody try this code ??

Edited by CorB
Link to post
Share on other sites

HI Lars,

 

Would be good to see your LCD work on this system too, using it on the MSP430 was very helpfull when developing. My efforts have proven unsuccessfull and I am moving back to do some work on my home-automation/sensing network using the MSP430. I will keep a close eye on development overhere.

 

cheers

Cor

Link to post
Share on other sites
  • 2 weeks later...

Hi,

 

After working on the library to make pins easily selected for Input/Ouput I tried mixing that coding into my SPI testfiles. The result is however still no succes, next step I will try is to simply bitbang the SPI on the C2000 pins. Luckily on Msp430 there;s enough examples to base the code on.

 

cheers

Cor

Link to post
Share on other sites

And finally success !! Bitbanging worked. Here's the rough code, the PinHigh etc commands come from the library that allows GPIO (and part of the ADC)-pins to be set easily.

 

EDIT: file with all used code attached.

 

void SPIWrite(uint16_t command, uint16_t data)
{
uint16_t spidata;
char bits;

spidata = command<<15;
spidata = spidata | data <<7;

PinLow(CS_PIN); // pull CS LOW
PinLow(SCL_PIN); // start clock LOW

for (bits=0; bits<16; bits++) // 9 bits output
{
PinLow(SCL_PIN); // start clock LOW


if (spidata & 0x8000)
{ //check MSB bit and set data line accordingly
PinHigh(MOSI_PIN);
}
else
{ PinLow(MOSI_PIN);

}
PinHigh(SCL_PIN); // end bit clock high -> send data on rising edge


spidata <<= 1; // shift a bit to the left
}

PinHigh(CS_PIN);


}

LCD_SPI.zip

Link to post
Share on other sites

CorB,

 

Were you able to get the LCD working?

 

I took a look two weeks ago at this and it appears the SPI FIFOs will spit out a few characters of garbage if they are not initialized correctly. I'll try to come to a full understanding of the issue this week and provide a fix in the next controlSUITE release.

Link to post
Share on other sites

Hey CorB, looks like we have been working on the same project. Ive also written some code (needs tidying still but will post when Im happy) to drive these LCDs. As Ive been using mine for the $4.30 booster pack using Hardware SPI wasn't an option for me so I was bit banging too. As there was ADC pins used I also used your code for setting GPIO pins.. lol..

 

Given the extra ram on the C2000 I think it should be possible to code up a reasonable graphics library (add to buffer and then chuck out the whole buffer to the LCD).

 

Anyways.. Thanks for the GPIO lib.. made things a lot easier to get my head around.

 

Dan

Link to post
Share on other sites

Hi Dan,

 

For the GLCD from Lars I allready have a simple graphics lib in development, now we can use this on the C2000 it will be a lot easier to implement real graphics. The major problem on MSP430 was that we had too little memory available to put the full screen into memory. Now we can use 96*8 bytes to store pixelinformation and a simple pixelsetting/clearing library should be no problem. I will move this now to a new topic (project) called GLCD on C2K launchpad.

 

cheers

 

Cor

Link to post
Share on other sites

CorB,

 

I solved the issues with the original example. It turns out the order in which the FIFO register bit fields are configured is important. To the best of my knowledge this isn't documented in the user guide for the SPI peripheral. If you replace the initialization code with the following code you should see the example start working. I'm glad you were able to get the LCD working and I think a good next step would be to try to get the LCD working using the actual SPI peripheral.

 

Cheers!

 

void spi_init()
{

SPI_reset(mySpi);
SPI_enable(mySpi);

// Reset on, rising edge, 16-bit char bits
SPI_setCharLength(mySpi, SPI_CharLength_16_Bits);
SPI_enableLoopBack(mySpi);

// Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SPI_setMode(mySpi, SPI_Mode_Master);
SPI_enableTx(mySpi);
SPI_enableOverRunInt(mySpi);
SPI_enableInt(mySpi);

SPI_setBaudRate(mySpi, (SPI_BaudRate_e)0x63);

// // Initialize SPI FIFO registers
SPI_enableFifoEnh(mySpi);
SPI_enableChannels(mySpi);
SPI_resetTxFifo(mySpi);
SPI_clearTxFifoInt(mySpi);
SPI_setTxFifoIntLevel(mySpi, SPI_FifoLevel_2_Words);
SPI_enableTxFifoInt(mySpi);

SPI_resetRxFifo(mySpi);
SPI_setRxFifoIntLevel(mySpi, SPI_FifoLevel_2_Words);
SPI_enableRxFifoInt(mySpi);
SPI_clearRxFifoInt(mySpi);

SPI_setTxDelay(mySpi, 0);

// Set so breakpoints don't disturb xmission
SPI_setPriority(mySpi, SPI_Priority_FreeRun);

SPI_enable(mySpi);

SPI_enableTxFifo(mySpi);
SPI_enableRxFifo(mySpi);

}

 

EDIT: Crap! I forgot I changed a few things in driverlib. I'll upload a new version of that as well. Look for a real controlSUITE release later this week/next week.

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...