AnsweredAssumed Answered

STM32F411VE Master-->SPI--> MAX7219 Slave

Question asked by tom.abel on Mar 3, 2018
Latest reply on Mar 6, 2018 by tom.abel

SPI connection with 7 Segment Serial LED DisplayHi,

 

 I beleive i have initialised my master STM32 correctly somehow i cant get my slave to understand my master.

My problem is my slave does not seem to understand the master, i have tried various things, like using SPI2 instead of SPI1, did not work, any help would be appreciated.

 

 

void init_spi_gpio(void)
{
     GPIO_InitTypeDef SPI_GPIOStruct;


     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

     /*
      * PB3 - SCK
      * PB4 - MISO
      * PB5 - MOSI
      * */

     SPI_GPIOStruct.GPIO_Mode = GPIO_Mode_AF;
     SPI_GPIOStruct.GPIO_OType = GPIO_OType_OD;
     SPI_GPIOStruct.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
     SPI_GPIOStruct.GPIO_PuPd = GPIO_PuPd_UP;
     SPI_GPIOStruct.GPIO_Speed = GPIO_Speed_100MHz;

     GPIO_Init(GPIOB, &SPI_GPIOStruct);

     GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_SPI1);
     GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_SPI1);
     GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_SPI1);

     /*NSS Pin Config */
     GPIO_InitTypeDef SPI_SSPIN_Struct;
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

     SPI_SSPIN_Struct.GPIO_Mode = GPIO_Mode_OUT;
     SPI_SSPIN_Struct.GPIO_OType = GPIO_OType_PP;
     SPI_SSPIN_Struct.GPIO_Pin = GPIO_Pin_15;
     SPI_SSPIN_Struct.GPIO_PuPd = GPIO_PuPd_UP;
     SPI_SSPIN_Struct.GPIO_Speed = GPIO_High_Speed;

     GPIO_Init(GPIOA, &SPI_SSPIN_Struct);
     //GPIO_SetBits(GPIOA,GPIO_Pin_15);
}
void init_spi_module(void)
{

     SPI_InitTypeDef SPI_InitStruct;

     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

     SPI_StructInit(&SPI_InitStruct);
     SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
     SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge;
     SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low;
     //SPI_InitStruct.SPI_CRCPolynomial = 0x00;
     SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b;
     SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
     SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_LSB;
     SPI_InitStruct.SPI_Mode = SPI_Mode_Master;
     SPI_InitStruct.SPI_NSS = SPI_NSS_Soft| SPI_NSSInternalSoft_Set;

     SPI_Init(SPI1, &SPI_InitStruct);
     SPI_Cmd(SPI1, ENABLE);
}

int main(void)
{
     uint8_t RxChar;
     SystemInit();
     SysTick_Init();
     RCC_HSICmd(ENABLE);

     init_led_gpios();
     init_spi_gpio();
     init_spi_module();
     init_usart2_comm_module();
     init_usart2_gpio();
     init_powerup();
     USART_TX_string("Reset!\n\r");
     GPIO_SetBits(GPIOD, GPIO_Pin_12);
     while (1)
     {
          write_to_MAX7219(0x0A, 0x05);
          Delay_ms(500);
          MAX7219_displayNumber(25);
     }
}


void write_to_MAX7219(uint8_t addr, uint8_t data)
{
     uint16_t Addr, Data, Data_to_send;
     Addr = (uint16_t)addr;
     Data = (uint16_t)data;
     Data_to_send = ( (Addr<<8 ) & 0xFF00 ) | Data ;
     GPIO_ResetBits(GPIOA,GPIO_Pin_15);
     SPI_send_word(  Data_to_send );
     GPIO_SetBits(GPIOA,GPIO_Pin_15);
}

void SPI_send_word(uint16_t byte)
{
     while ( ( (SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_BSY) ) == SET))
                         ;
     SPI_I2S_SendData(SPI1, (uint16_t) byte);
     while ( ( (SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE) ) != SET))
                         ;
}



Outcomes