This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SPI1 CMSIS STM32F407VG

Hello. Hope it's the right forum to ask such questions. I'm a newbie, using stm32f407VG discovery board, trying to configure SPI1, but it seems it doesn't work. I'm trying to make the nrf24l01 work and the module itself seems to be ok because it works with Arduino. So, what's wrong with my code? P.S. CE port-PA3, CSN-PA4

#ifndef SPI_H
#define SPI_H
#include "stm32f4xx.h"
void SPI1_init(void){
	RCC->AHB1ENR |= 1;
	RCC->APB2ENR |= 0x1000;
	
	GPIOA->MODER &= ~0x0000FC00;
	GPIOA->MODER |= 0x0000A800;
	GPIOA->AFR[0] &= ~0xF0F00000;
	GPIOA->AFR[0] |= 0x50500000;
	
	GPIOA->MODER &= ~0x00000300;
	GPIOA->MODER |= 0x00000100;
	GPIOA->MODER &= ~(3<<6);
	GPIOA->MODER |= (1<<6);
	SPI1->CR1 = 0x31C;
	SPI1->CR2 = 0;
	SPI1->CR1 |= 0x40;
}
void SPI1_write(unsigned char data){
	while(!(SPI1->SR & 2));
	//GPIOA->BSRRH = 0x0010;
	SPI1->DR = data;
	while(!(SPI1->SR & 0x80));
	//GPIOA->BSRRL = 0x0010;
}
unsigned char SPI1_read(void){
	while(!(SPI1->SR & SPI_SR_RXNE));
	//GPIOA->BSRRH = 0x0010;
	return SPI1->DR;
	//GPIOA->BSRRL = 0x0010;
}
uint8_t SPI_comm(uint8_t data){
	while(!(SPI1->SR & 2));
	//GPIOA->BSRRH = 0x0010;
	SPI1->DR = data;
	while(!(SPI1->SR & SPI_SR_RXNE));
	data = SPI1->DR;
	//GPIOA->BSRRL = 0x0010;
	return data;
}
void SPI1_bufWrite(uint8_t * buf, uint8_t size){
	for(uint8_t i=0;i<size;i++){
		while(!(SPI1->SR & 2));
		SPI1->DR = buf[i];
		while(!(SPI1->SR & 0x80));
	}
}
void SPI1_bufRead(uint8_t * buf, uint8_t size){
	for(uint8_t i=0;i<size;i++){
		while(!(SPI1->SR & SPI_SR_RXNE));
		buf[i]=SPI1->DR;
	}
}
#endif
void CSN_L(void){
	GPIOA->BSRRH = 0x0010;
}
void CSN_H(void){
	GPIOA->BSRRL = 0x0010;
}
void CE_L(void){
	GPIOA->BSRRH = (1<<3);
}
void CE_H(void){
	GPIOA->BSRRL = (1<<3);
}