This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GH6PM: Baremetal max6675 code (through Keil) using Texas Tiva C

Part Number: TM4C123GH6PM

I realize this is a forum for TI based compilers but I'm trying to make the Max6675 thermocouple with SPI work and cannot seem to get it to. All my settings are correct but when it comes to receiving, it just doesn't occur, that is the SSI1->DR remains empty even though everything is plugged in correctly with respect to pinout and I'm operating at a relatively low clock speed at 10 kHz. Shown below is the code, can anyone offer any suggestions? 


#include "TM4C123.h" // Device header
#include <stdint.h>


void SSI1_INIT(void);
void SSI1_READ_TEMP();
void Timer0AMsDelay(int delay);


int main(){


SSI1_INIT();

Timer0AMsDelay(1000);
SSI1_READ_TEMP();


while(1){}

}

void SSI1_INIT(void){

SYSCTL->RCGCSSI |= 0x02; //Enable clock for SSI1
SYSCTL->RCGCGPIO |= 8; //Enable clock for GPIOD
SYSCTL->RCGCGPIO |= 0x20; //Enable clock for GPIOF

GPIOD->AMSEL &= ~0x05; /* disable analog for these pins */
GPIOD->DEN |= 0x05; //Digital enable GPIOD, pin 0 and pin 2
GPIOD->AFSEL |= 0x05; //Alternate function enable GPIOD, pin 0 and pin 2
GPIOD->PCTL &= ~0x00000F0F;
GPIOD->PCTL |= 0x00000202; //Enable SSI1 SCK for GPIOD, pin 0 and SSI1 RX for GPIOD, pin 2. p1351 0010 0000 0010

GPIOF->DEN |= 0x04; //Digitally enable GPIOF, pin 2
GPIOF->DIR |= 0x04; //GPIOF, pin 2 set as output
GPIOF->PUR |= 0x4; //GPIOF, pin 2 set as output
GPIOF->DATA |= 0x04; //


SSI1->CR1 = 0; //Clear enable bit to change parameters
SSI1->CC = 0; //
SSI1->CPSR |= 0x20; /* prescaler divided by 32*/
SSI1->CR0 |= 0x310F; /* Further clock div by 50 to get 10 kHz, SPI mode master,
16 bit data, CPOL = 0, CPHA = 1 --> 0b 0011 0001 0000 1111 */
SSI1->CR1 |= 0x2; /* enable SSI1 */

}


void SSI1_READ_TEMP(){
uint16_t data = 0;
GPIOF->DATA &= ~0x04;
while(!(SSI1->SR & 0x8)){} //p974 - wait here while Receive Not Empty is true
data = SSI1->DR; //Write data to data register
while(SSI1->SR & 0x10){} //p974 - wait here while SSI is busy
GPIOF->DATA |=0x04;
}


void Timer0AMsDelay(int delay){

SYSCTL->RCGCTIMER |= 1;
TIMER0->CTL = 0;
TIMER0->CFG = 0x04;
TIMER0->TAMR = 0x02;
TIMER0->TAILR = 16000 - 1;
TIMER0->ICR = 0x1;
TIMER0->CTL = 0x01;

for(int i = 0; i < delay; i++)
{
while((TIMER0->RIS & 0x1) == 0){}
TIMER0->ICR = 0x1;
}

}

  • Hello Brendan,

    Using Keil isn't much of an issue, but we do not support direct register code for TM4C as noted in our forum guidelines #4: https://e2e.ti.com/support/microcontrollers/other/f/908/t/695568

    That said you may be using the wrong flag for your while loop:

    #define SSI_SR_RFF              0x00000008  // SSI Receive FIFO Full
    #define SSI_SR_RNE              0x00000004  // SSI Receive FIFO Not Empty

    Something to check when looking at you did vs SSIDataGet TivaWare API.

    You may want to use TivaWare API to validate how you need to communicate with the device and then review the source code to put together your application.