AnsweredAssumed Answered

STM32F429 Discovery SPI Registers

Question asked by CodyMacaroni on Aug 21, 2014
Latest reply on Aug 22, 2014 by Andrew Neil

I am trying to use the STM32F429 Discovery board in order to communicate in a transmit only mode to an LCD over SPI. However, every time I write to the data register to output, I see nothing get loaded in my debugging view (CrossStudio). I'm using Pin 4 for my CSS.

#include "stm32f4xx.h"
//#include "tm_stm32f4_spi.h"
 
 
 
 
#define MODE_CLEAR (1 << 5) /* M0:M2 = 0b001 = 1 */
#define MODE_UPDATE (4 << 5)    /* M0:M2 = 0b100 = 4 */
#define MODE_DISPLAY (0 << 5)   /* M0:M2 = 0b000 = 0 */
 
unsigned char transmitData[20];
 
int main(void) {
        int dummy;
    int j;
 
        SET_BIT(RCC->AHB1ENR,(RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIOAEN) );
 
 
        MODIFY_REG(GPIOC->MODER,
                   (GPIO_MODER_MODER10 | GPIO_MODER_MODER12)  ,
                   (GPIO_MODER_MODER10_1 | GPIO_MODER_MODER12_1) ); // Sets to alternate function
     
        SET_BIT(GPIOC->OTYPER, (GPIO_OTYPER_OT_10 | GPIO_OTYPER_OT_12)); // Set output to push-pull type
        CLEAR_BIT(GPIOC->PUPDR, (GPIO_PUPDR_PUPDR10 | GPIO_PUPDR_PUPDR12) ); // Disable push pull resistors
    SET_BIT(GPIOC->OSPEEDR, (GPIO_OSPEEDER_OSPEEDR10 | GPIO_OSPEEDER_OSPEEDR12) ); // Set speed high
         /* Set the Alternate Function for the SPI3 pins */
       // Port C Pins 7-0
        GPIOC->AFR[0] = 0x00000000; // PTC lower order pins are default
        // Port C Pins 15-8
        GPIOC->AFR[1] = 0x00066600; // PTC pins 10, 11, and 12 are for SPI (AF6 = 0x6)
    
        // Set up SS for screen
        MODIFY_REG(GPIOA->MODER, GPIO_MODER_MODER4 , GPIO_MODER_MODER4_0 );
 
        SET_BIT(GPIOA->BSRRL, 0b10000); //Sets pin 4 high
 
 
         
         
 
       // Enable the peripheral clock for SPI3
        SET_BIT(RCC->APB1ENR, RCC_APB1ENR_SPI3EN);
        CLEAR_BIT(SPI3->CR1, SPI_CR1_CPHA);
        SET_BIT(SPI3->CR1, SPI_CR1_CPOL);
        //SET_BIT(SPI3->CR1, SPI_CR1_BIDIMODE);
        //SET_BIT(SPI3->CR1, SPI_CR1_BIDIOE);
        SET_BIT(SPI3->CR1, SPI_CR1_SSM);// Needed to enable single master
        SET_BIT(SPI3->CR1, SPI_CR1_SSI);// Needed to enable single master
        SET_BIT(SPI3->CR1, SPI_CR1_MSTR); // Set Master configuration
        /* TODO: Set Baud to 2 MHz (not just a random prescaler) */
        MODIFY_REG(SPI3->CR1, SPI_CR1_BR, SPI_CR1_BR); //Set to fCLK/256
        CLEAR_BIT(SPI3->CR1, SPI_CR1_LSBFIRST); // write out MSB first
        SET_BIT(SPI3->CR1, SPI_CR1_SPE); // Enable SPI3
 
    transmitData[0]= MODE_CLEAR;
    transmitData[1]=0x00;
     
        
        for(j = 0; j < 2; j++) {
            //TM_SPI_Send(SPI3, transmitData[j]);
                          SPI3->DR = transmitData[j]; // Write data to the data register
                        while( !(READ_BIT(SPI3->SR, SPI_SR_TXE)) ); // Wait until transmit is complete
                        while( READ_BIT(SPI3->SR, SPI_SR_BSY) );
                        dummy = SPI3->DR;
        }
                SET_BIT(GPIOA->BSRRH, 0b10000); //Sets pin 4 low
         
 
         
         
         
    while(1){  
         
    transmitData[0]= MODE_UPDATE;
    transmitData[1]=0x00;
     
         
        SET_BIT(GPIOA->BSRRL, 0b10000); //Sets pin 4 high
 
                for(j = 0; j < 2; j++) {
            //TM_SPI_Send(SPI3, transmitData[j]);
                        SPI3->DR = transmitData[j]; // Write data to the data register
                        while( !(READ_BIT(SPI3->SR, SPI_SR_TXE)) ); // Wait until transmit is complete
                        while( READ_BIT(SPI3->SR, SPI_SR_BSY) );
                }
         
        SET_BIT(GPIOA->BSRRH, 0b10000); //Sets pin 4 low
                
     
    transmitData[0]=0x80; //UPDATE LINE
    transmitData[1]=0xD2;  
    transmitData[2]=0xF0;
    transmitData[3]=0xF0;
    transmitData[4]=0xF0;
    transmitData[5]=0xF0;
    transmitData[6]=0xF0;
    transmitData[7]=0xF0;
    transmitData[8]=0xF0;
    transmitData[9]=0xF0;
    transmitData[10]=0xF0;
    transmitData[11]=0xF0;
    transmitData[12]=0xF0;
    transmitData[13]=0xF0;
    transmitData[14]=0xF0;
    transmitData[15]=0xF0;
    transmitData[16]=0xF0;
    transmitData[17]=0xF0;
    transmitData[18]=0x00;
    transmitData[19]=0x00;
     
    //Send update message over SPI1 forever
 
        SET_BIT(GPIOA->BSRRL, 0b10000); //Sets pin 4 high
         
                for(j = 0; j < 20; j++) {
            //TM_SPI_Send(SPI3, transmitData[j]);
                        SPI3->DR = transmitData[j]; // Write data to the data register
                        while( !(READ_BIT(SPI3->SR, SPI_SR_TXE)) ); // Wait until transmit is complete
                        while( READ_BIT(SPI3->SR, SPI_SR_BSY) );
                }
        //osDelay(10);
        SET_BIT(GPIOA->BSRRH, 0b10000); //Sets pin 4 low
                 
         
         
    transmitData[0]=0x80; //UPDATE LINE
    transmitData[1]=0x52;  
    transmitData[2]=0x0F;
    transmitData[3]=0x0F;
    transmitData[4]=0x0F;
    transmitData[5]=0x0F;
    transmitData[6]=0x0F;
    transmitData[7]=0x0F;
    transmitData[8]=0x0F;
    transmitData[9]=0x0F;
    transmitData[10]=0x0F;
    transmitData[11]=0x0F;
    transmitData[12]=0x0F;
    transmitData[13]=0x0F;
    transmitData[14]=0x0F;
    transmitData[15]=0x0F;
    transmitData[16]=0x0F;
    transmitData[17]=0x0F;
    transmitData[18]=0x00;
    transmitData[19]=0x00;
     
    //Send update message over SPI1 forever
 
        SET_BIT(GPIOA->BSRRL, 0b10000); //Sets pin 4 high
         
                for(j = 0; j < 20; j++) {
            //TM_SPI_Send(SPI3, transmitData[j]);
                        SPI3->DR = transmitData[j]; // Write data to the data register
                        while( !(READ_BIT(SPI3->SR, SPI_SR_TXE)) ); // Wait until transmit is complete
                        while( READ_BIT(SPI3->SR, SPI_SR_BSY) );
                }
         
        SET_BIT(GPIOA->BSRRH, 0b10000); //Sets pin 4 low
                 
         
        transmitData[0]= MODE_DISPLAY;
        transmitData[1]=0x00;
 
         
        SET_BIT(GPIOA->BSRRL, 0b10000); //Sets pin 4 high
         
                for(j = 0; j < 2; j++) {
            //TM_SPI_Send(SPI3, transmitData[j]);
                        SPI3->DR = transmitData[j]; // Write data to the data register
                        while( !(READ_BIT(SPI3->SR, SPI_SR_TXE)) ); // Wait until transmit is complete
                        while( READ_BIT(SPI3->SR, SPI_SR_BSY) );
                }
         
        SET_BIT(GPIOA->BSRRH, 0b10000); //Sets pin 4 low
                 
     
         
 
    }
}

Outcomes