0

I try to send data from master to slave using SPI,

I'm really new to this and I dont know what im doing wrong

I dont know if its something with my init configuration or my understanding from spi proccess. if someone know or can guide me over cause Im out of clue what went wrong.


void SPI_init_master(void){
    RCC->AHBENR |= RCC_AHBENR_GPIOBEN; // enable port b clock
    RCC->APB2ENR |= RCC_APB2ENR_SPI1EN; // enable spi clock
    GPIOB->MODER |= 0x00000A80;     // Configure GPIOB pins 3 and 4 and 5 as alternate function 5
    // AFR[0] is the same as AFRL in the reference manual (p. 241)
    GPIOB->AFR[0] |= 0x00555000;    // configure PB3-PB5
//  SPI1->CR1 |= 0x0044; // enable SPI and Master configuration
     SPI1->CR1 |=  (SPI_CR1_SPE | SPI_CR1_MSTR);
}


void SPI_write(uint8_t ch){
    *(__IO uint8_t *)&SPI1->DR = ch;
    while(!(SPI1->SR & SPI_SR_TXE)); // wait until Transmit buffer empty will be 1 - finish to transmit data and the transmit buffer empty
    print("spi_write - data in DR is: ");
    USART2_printCharacter(ch);
    print("\n");
}


char SPI_read(void)
{
    char ch;
    while(!(SPI1->SR & SPI_SR_RXNE));// wait until Receive buffer not empty will be 1 - finish to transmit data and the transmit buffer not empty
    ch = SPI1->DR;
    print("spi_read - data in DR is: ");
    USART2_printCharacter(ch);
    print("\n");
    return ch;
}
Try2prog
  • 161
  • 10
  • How do you test it? What is the expected behavior and what is going on instead? – Tagli Jun 09 '21 at 10:21
  • i have 2 boards and I try to catch from debugger on slave any data from DR - I expect to get 1/2/3 to turn on led/blink. but I cant catch any change on SPI_SR_RXNE in slave. I connect with 2 laptops for both debugging. (and mosi/miso/sck on pb3-5) – Try2prog Jun 09 '21 at 11:16
  • 1
    Please describe the test setup. What is the master sending? What is it receiving? Please also show the slave code. – Codo Jun 09 '21 at 12:42
  • It would be great if you provide the test setup diagram/schematic. – LVitya Jun 13 '21 at 20:04

0 Answers0