TM4C123GH6PM with SPI Receive - Data Register remains 0
Apparently this exact question was asked but never answered 13 years ago as the asker never uploaded their code so I'll ask. 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 SSI1SYSCTL->RCGCGPIO |= 8; //Enable clock for GPIODSYSCTL->RCGCGPIO |= 0x20; //Enable clock for GPIOF
GPIOD->AMSEL &= ~0x05; /* disable analog for these pins */GPIOD->DEN |= 0x05; //Digital enable GPIOD, pin 0 and pin 2GPIOD->AFSEL |= 0x05; //Alternate function enable GPIOD, pin 0 and pin 2GPIOD->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 2GPIOF->DIR |= 0x04; //GPIOF, pin 2 set as outputGPIOF->PUR |= 0x4; //GPIOF, pin 2 set as outputGPIOF->DATA |= 0x04; //
SSI1->CR1 = 0; //Clear enable bit to change parametersSSI1->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 truedata = SSI1->DR; //Write data to data registerwhile(SSI1->SR & 0x10){} //p974 - wait here while SSI is busyGPIOF->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;}
GreenhouseCoder said:this exact question was asked but never answered 13 years ago
How about a link for context?
Note that the operation of the SPI is nothing to do with ARM or Keil:
https://community.arm.com/developer/tools-software/tools/f/keil-forum/43684/lpc2148-timer0-not-working-as-expected/158950#158950
so you'd be better asking TI about that:
https://www.ti.com/product/TM4C123GH6PM#support-training