Hi
I am new to the embedded processors world and am trying to get my first SPI interface to work.
I am trying to tackle it by first getting the micro controller side pins to take on their correct values.
In particular I have had no luck getting a clock signal on the CLK out pin. I downloaded a program from
Jonathan Valvano's "starter files" page. See the listing below. While the original file used an external device
(DAC) I have tried to make a generic interface that anyone developing spi code on a TM4C platform might find
helpful - esp when starting out. The code below compiles without errors. I connect an oscilloscope to pin PA2
and get no response. I was of course expecting a square wave timing signal.
The code is fairly low level C - I can't see exactly which line of code sets up PA2 as the clk signal.
Any tips on getting this working would be most appreciated.
//Cut down version (microcontroller side of SPI - debug) of a program from the site:
// users.ece.utexas.edu/.../
// Original Author J.Valvano
// Original program: MAX549_4C123.zip For TM4C123 board
#include <stdint.h>
#include "SysTick.h"
#include <stdio.h>
#include <stdlib.h>
#include "C:/ti/TivaWare_C_Series-2.1.2.111/inc/tm4c123gh6pm.h"
// example pins on the generic spi peripheral (excluded here to debug the MC side.)
// to be tested with an oscilloscope - like the clock signal
// Pin 1 ground
// Pin 2 OUTA
// Pin 3 CS, SSI0Fss connected to PA3
// Pin 4 DIN, SSI0Tx connected to PA5
// Pin 5 SCLK SSI0Clk connected to PA2
// Pin 6 OUTB
// Pin 7 REF (cheap solution connects this to +3.3V)
// Pin 8 +3.3V
#define SSI_CR0_SCR_M 0x0000FF00 // SSI Serial Clock Rate
#define SSI_CR0_SPH 0x00000080 // SSI Serial Clock Phase
#define SSI_CR0_SPO 0x00000040 // SSI Serial Clock Polarity
#define SSI_CR0_FRF_M 0x00000030 // SSI Frame Format Select
#define SSI_CR0_FRF_MOTO 0x00000000 // Freescale SPI Frame Format
#define SSI_CR0_DSS_M 0x0000000F // SSI Data Size Select
#define SSI_CR0_DSS_16 0x0000000F // 16-bit data
#define SSI_CR1_MS 0x00000004 // SSI Master/Slave Select
#define SSI_CR1_SSE 0x00000002 // SSI Synchronous Serial Port
#define SSI_SR_RNE 0x00000004 // SSI Receive FIFO Not Empty
#define SSI_SR_TNF 0x00000002 // SSI Transmit FIFO Not Full
// Enable
#define SSI_CPSR_CPSDVSR_M 0x000000FF // SSI Clock Prescale Divisor
int main(void){
uint8_t data = 7;
printf("Setup SPI\n");
// assumes: system clock rate less than 20 MHz
SYSCTL_RCGCSSI_R |= 0x01; // activate SSI0
SYSCTL_RCGCGPIO_R |= 0x01; // activate port A
while((SYSCTL_PRGPIO_R&0x0001) == 0){};// ready?
GPIO_PORTA_AFSEL_R |= 0x2C; // enable alt funct on PA2,3,5
GPIO_PORTA_DEN_R |= 0x2C; // enable digital I/O on PA2,3,5
// configure PA2,3,5 as SSI
GPIO_PORTA_PCTL_R = (GPIO_PORTA_PCTL_R&0xFF0F00FF)+0x00202200;
GPIO_PORTA_AMSEL_R = 0; // disable analog functionality on PA
SSI0_CR1_R &= ~SSI_CR1_SSE; // disable SSI
SSI0_CR1_R &= ~SSI_CR1_MS; // master mode
// clock divider for 8 MHz SSIClk (assumes 16 MHz PIOSC)
SSI0_CPSR_R = (SSI0_CPSR_R&~SSI_CPSR_CPSDVSR_M)+2;
SSI0_CR0_R &= ~(SSI_CR0_SCR_M | // SCR = 0 (8 Mbps data rate)
SSI_CR0_SPH | // SPH = 0
SSI_CR0_SPO); // SPO = 0
// FRF = Freescale format
SSI0_CR0_R = (SSI0_CR0_R&~SSI_CR0_FRF_M)+SSI_CR0_FRF_MOTO;
// DSS = 16-bit data
SSI0_CR0_R = (SSI0_CR0_R&~SSI_CR0_DSS_M)+SSI_CR0_DSS_16;
SSI0_DR_R = data; // load 'data' into transmit FIFO
SSI0_CR1_R |= SSI_CR1_SSE; // enable SSI
}
cheers, Tim