Select Page

DAC LTC1661 on EduARM4 Trainer Board

DAC LTC1661 on EduARM4 Trainer Board

Fig:TM4C123 LaunchPad to LTC1661 Connection on EduARM4 Trainer Board

Note: Short 1 & 2 of J8 (EduARM4 Trainer Board)

Configuring SSI for SPI data transmission

After the GPIO configuration, we need to take the following steps to configure the SSI for the SPI protocol:

  1. Enable the clock to SSI module using RCGCSSI (SYSCTL_RCGCSSI_R).
  2. Disable the SSI via bit 1 of SSICR1 (SSIn_CR1_R) register before initialization.
  3. Set the Bit Rate with the SSICPSR (SSIn_CPSR_R) prescaler and SSICR0 (SSIn_CR0_R) control registers.
  4. Also select the SPI mode, phase, polarity, and data size in SSICR0 (SSIn_CR0_R) control register.
  5. Select the master mod in SSISCR1 (SSIn_CR1_R) register.
  6. Enable SSI using SSICR1 (SSIn_CR1_R) register.
  7. Assert slave select signal.
  8. Wait until the TNF flag (transmit FIFO not full) in SSISR (SSIn_SR_R status register) goes high, then load a byte of data into SSIDR (SSIn_DR_R data register) to be transmitted.
  9. Repeat step 8 above until all the data are in the FIFO.
  10. Wait until transmit is complete (transmit FIFO empty and SSI not busy).
  11. Deassert the slave select signal.

(where n = 0 to 3)

SPI Examples and Tasks

Sample Program

  1. /*
  2.  * Using SSI1 to send A to Z characters via SPI1
  3. */
  4. 
    
  5. #include <stdint.h>
  6. #include "inc/tm4c123gh6pm.h"
  7. 
    
  8. void Init_SSI1(void);
  9. void SSI1_Write(unsigned char data);
  10. 
    
  11. int main(void)
  12. {
  13.     unsigned char i;
  14. 
    
  15.     Init_SSI1();
  16. 
    
  17.     for(;;) {
  18.         for (i = 'A'; i <= 'Z'; i++) {
  19.             SSI1_Write(i);      /* write a character */
  20.         }
  21.     }
  22. }
  23. 
    
  24. void SSI1_Write(unsigned char data)
  25. {
  26.     GPIO_PORTF_DATA_R &= ~0x04;  /* assert SS low */
  27. 
    
  28.     while((SSI1_SR_R & 2) == 0)
  29.         ;                        /* wait until FIFO not full */
  30.     SSI1_DR_R = data;            /* transmit high byte */
  31. 
    
  32.     while(SSI1_SR_R & 0x10)
  33.         ;                        /* wait until transmit complete */
  34.     GPIO_PORTF_DATA_R |= 0x04;   /* keep SS idle high */
  35. }
  36. 
    
  37. void Init_SSI1(void)
  38. {
  39.     SYSCTL_RCGCSSI_R |= 2;       /* enable clock to SSI1 */
  40.     SYSCTL_RCGCGPIO_R |= 8;      /* enable clock to GPIOD for SSI1 */
  41.     SYSCTL_RCGCGPIO_R |= 0x20;   /* enable clock to GPIOF for slave select */
  42. 
    
  43.     /* configure PORTD 3, 1 for SSI1 clock and Tx */
  44.     GPIO_PORTD_AMSEL_R &= ~0x09; /* disable analog for these pins */
  45.     GPIO_PORTD_DEN_R |= 0x09;    /* and make them digital */
  46.     GPIO_PORTD_AFSEL_R |= 0x09;  /* enable alternate function */
  47.     GPIO_PORTD_PCTL_R &= ~0x0000F00F; /* assign pins to SSI1 */
  48.     GPIO_PORTD_PCTL_R |= 0x00002002;  /* assign pins to SSI1 */
  49. 
    
  50.     /* configure PORTF 2 for slave select */
  51.     GPIO_PORTF_DEN_R |= 0x04;    /* make the pin digital */
  52.     GPIO_PORTF_DIR_R |= 0x04;    /* make the pin output */
  53.     GPIO_PORTF_DATA_R |= 0x04;   /* keep SS idle high */
  54. 
    
  55.     /* SPI Master, POL = 0, PHA = 0, clock = 4 MHz, 16 bit data */
  56.     SSI1_CR1_R = 0;             /* disable SSI and make it master */
  57.     SSI1_CC_R = 0;              /* use system clock */
  58.     SSI1_CPSR_R = 2;            /* prescaler divided by 2 */
  59.     SSI1_CR0_R = 0x0007;        /* 8 MHz SSI clock, SPI mode, 8 bit data */
  60.     SSI1_CR1_R |= 2;            /* enable SSI1 */
  61. }