Jump to content
43oh

Solved: SPI bit rate (EK-TM4C1294XL Launchpad)


Recommended Posts

As my first "real" project on the TM4C129x series, I am trying to port my software for the Nokia 5100 LCD (originally written for the ATMega series). I seem to having issues setting the PWM bit rate. Here are the functions for setting up SPI on SSI3:

#include "Nokia5110_LCD.h"

// PORT K
#define CS  GPIO_PIN_7
#define RST GPIO_PIN_6
#define BACKL GPIO_PIN_4
#define DC  GPIO_PIN_5

// private function prototypes
void LCDWrite(uint8_t dc, uint8_t data);

void Nokia5110LCDIni(void) {

    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ); // used for SSI: tx, rx, clk
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK); // used for CS, RST, BACKL, DC
    MAP_GPIOPinWrite(GPIO_PORTQ_BASE, GPIO_PIN_0|GPIO_PIN_2|GPIO_PIN_3, 0xff); // all control pins high: LCD off
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, CS|RST|BACKL|DC);  //

    uint32_t ui32_TReset=MAP_SysCtlClockGet()*3*.0000002; // 200 ns delay
    MAP_GPIOPinWrite(GPIO_PORTK_BASE, RST, 0); // RST
    MAP_SysCtlDelay(ui32_TReset); // hold L
    MAP_GPIOPinWrite(GPIO_PORTK_BASE, RST, 0xff); //

    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3);

	//MAP_SSIDisable(SSI3_BASE); // pure paranoia
    MAP_SSIConfigSetExpClk( SSI3_BASE,
    						MAP_SysCtlClockGet(),
    						SSI_FRF_MOTO_MODE_0,
    						SSI_MODE_MASTER,
    						100000,
    						8);

    MAP_GPIOPinConfigure(GPIO_PQ0_SSI3CLK);
    //MAP_GPIOPinConfigure(GPIO_PQ1_SSI3FSS);
    MAP_GPIOPinConfigure(GPIO_PQ2_SSI3XDAT0); //tx
    MAP_GPIOPinConfigure(GPIO_PQ3_SSI3XDAT1); //rx

    MAP_GPIOPinTypeSSI(GPIO_PORTQ_BASE, GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 );

	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3);

	MAP_SSIEnable(SSI3_BASE);

    LCDWrite(LCD_COMMAND, 0x21); // extended instruction set
    LCDWrite(LCD_COMMAND, 0xC8); // contrast
    LCDWrite(LCD_COMMAND, 0x06); // temp coeff
    LCDWrite(LCD_COMMAND, 0x13); // LCD bias mode 1:48.
    LCDWrite(LCD_COMMAND, 0x20); // standard commands, horiz mode
    LCDWrite(LCD_COMMAND, 0x0C); // nl mode
}


void LCDWrite(uint8_t dc, uint8_t data) {
    MAP_GPIOPinWrite(GPIO_PORTK_BASE, CS, 0); // enable LCD
    if ( dc == LCD_COMMAND ) {
        MAP_GPIOPinWrite(GPIO_PORTK_BASE, DC, 0); // low = command
	} else {
	    MAP_GPIOPinWrite(GPIO_PORTK_BASE, DC, 0xff ); //
	}
	MAP_SSIDataPut(SSI3_BASE, data);
    while (MAP_SSIBusy(SSI3_BASE)); /// finish operation
    MAP_GPIOPinWrite(GPIO_PORTK_BASE, DC, 0xff ); //  redundant, but nicer...
    MAP_GPIOPinWrite(GPIO_PORTK_BASE, CS, 0xff); // disable LCD
}

This is how the above code gets called:

/*
 * main.c
 */
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/ssi.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/pin_map.h"
#include "Nokia5110_LCD.h"


int main(void) {

	MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);

	Nokia5110LCDIni();

	while(1) {

	}

	return 0;
}

And here is what I see on the LA:

 

post-3920-1426460546218_thumb.png

 

The CPU is configured to run at 120 MHz and seems to be running at that frequency as far I I can tell from the duration of the RESET pulse I am generating (third row in the LA tracing). One byte gets transferred in about 10 µs, although I set the bit rate parameter in SSIConfigSetExpClk() to 100000, expecting a bit duration of 10 µs. Am I misunderstanding something here?

 

 

Thanks and best regards,

 

Fred

 

Link to post
Share on other sites

Istead of using SysCtlClockGet inside the SSIConfigSetExpClk() trie to actualy use 120000000. there is a error using that with the TM4C1294 series 

 

Look in TivaWare peripheral guide: 

This function can only be called on TM4C123 devices. For TM4C129 devices, the return value

from SysCtlClockFreqSet() indicates the system clock frequency.
Link to post
Share on other sites

 

Istead of using SysCtlClockGet inside the SSIConfigSetExpClk() trie to actualy use 120000000.    ...

Thank you very much, that is the solution.

I unsuccessfully looked through the ROM User's guide trying to find an equivalent for SystCtlClockGet() for the TM4C129 series, i.e. something like "SysCtlClockFreqGet()". Thus, I added the frequency as a constant as you suggested, and everything works now:

post-3920-14264605464632_thumb.png

Link to post
Share on other sites

I belive  SysCtlClockFreqSet() returns the actual clock. So the best is to save in a variable that return value istead of using  constant. I just sugested the constant for testing

Thanks. I will probably have to add that to my set of "personal standard includes and variables".

Link to post
Share on other sites

@@fhs

Remember that there are diferences from the TM4C123 to the TM4C1294. That's not the only TivaWare fuction that doesn't work in the TM4C1294.

 

I don't know them all from the top of my head right now but just wanted to alert you for that. The TivaWare peripheral guide has comments when it's family specific, the datasheet and the peripheral guide are always my goto PDFs  when i need infomation.

 

Here is the latest one, that is inside the TivaWare files. The one to download only the guide in TI website doesn't seem updated.

SW-TM4C-DRL-UG-2.1.0.12573.pdf

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