We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
HI everyone, i'm trying to do an a SPI communication between the board STM32F746 and the MAX7219 to controller a matrix. i'm working in keil uvision 5 and programming without libraries, DMA, CMSIS or other. i programm through registers putting '1'. i want a full-duplex communication, as slave and onliy are one slave. i add the code that i do. it's on spanish that is my languaje. i hope that all can understand me and solve this. thanks
// Code
/*
Pines:
PB3: SCL
PB4: MISO
PB5: MOSI
*/
// ************************ LIBRERIAS ************************
#include <stdio.h>
#include "STM32F7xx.h"
// ***********************************************************
// ************************ VARIABLES GLOBALES ***************
// ************************ FUNCIONES ************************
void enviar_datos(char comando, char dato){
char recibido=0;
// Espera mientras la busy flag esta activa
while(!(SPI3->SR & SPI_SR_TXE)){} // Mientas la busy flago esta en 1 no se
SPI3->DR=comando; //
while(SPI3->SR & SPI_SR_RXNE){} // Tiempo de espera mientras se vacia el buffer
recibido=SPI3->DR;
while(!(SPI3->SR & SPI_SR_TXE)){} // Mientas la busy flago esta en 1 no se puede tr
SPI3->DR=dato; //
}
char leer_datos(char direccion){
while(!(SPI3->SR & SPI_SR_TXE)){} // Mientas la busy flago esta en 1 no se puede
SPI3->DR=direccion; //
SPI3->DR=0x00; //
return SPI3->DR;
// ************************ INTERRUPCIONES *******************
extern "C"{
// ************************ MAIN *****************************
int main(void){
// ******************** PUERTOS **************************
RCC->AHB1ENR |=0x03; // Activo el puerto A y B
// *******************************************************
// ******************** PINES ****************************
GPIOA->MODER |=0x80000000; // Alternativo pin 15
GPIOA->AFR[1] =0x60000000; // Funcion alterna 6
GPIOB->MODER |=0xA80; // Alternativo pines 3 a 5
GPIOB->AFR[0] =0x666000; // Funcion alterna 6
// ******************** SPI ******************************
RCC->APB1ENR |=RCC_APB1ENR_SPI3EN; // Activo el Habilitador del SPI 3
SPI3->CR1 |=0x31; // Configuracion del BaudRate as 256
SPI3->CR1 |=SPI_CR1_CPHA; // Configuracion de la fase del SLC, la he
SPI3->CR1 |=SPI_CR1_CPOL; // Configuracion de la polaridad del Reloj,
SPI3->CR1 |=SPI_CR1_SSM; // Activo el asistente de slave select
SPI3->CR1 &=~SPI_CR1_RXONLY; // Configuracion para que la Full-duplex
SPI3->CR1 &=~SPI_CR1_BIDIMODE; // Configuracion para tener 2 lineas
SPI3->CR1 &=~SPI_CR1_LSBFIRST; // Configuracion para que se transmita
SPI3->CR1 |=SPI_CR1_CRCEN; // No necesito CRC
SPI3->CR1 |=SPI_CR1_MSTR; // Configuracion del SPI como MASTER
SPI3->CR1 |=SPI_CR1_SSI;
SPI3->CR1 &=~SPI_CR1_CRCL; // tamaño de 8 bits
// CR2
SPI3->CR2 |=0x700; // Configuracion del tamaño de la informacion a
SPI3->CR2 |=SPI_CR2_SSOE; // Activo el output SS para tener un unico
SPI3->CR2 &=~SPI_CR2_FRF; // SPI en modo normal
SPI3->CR2 &=~SPI_CR2_NSSP; // No deseo pulsos en la linea SS
SPI3->CR2 |=SPI_CR2_FRXTH; // Se activa la interrupcion Rx si recibe 8 bits
SPI3->CR1 |=SPI_CR1_SPE; // Activo el periferico
enviar_datos(0x04,0x00);
// ******************** MAIN *****************************
while(true){
Hi,
If you haven't looked at it yet, I'd suggest using the SPI CMSIS-Driver that ST and Keil have in the latest ST32F7 pack:
- If you go to:http://www.keil.com/dd2/pack/#Keil.STM32F7xx_DFP
- and expand the "STMicroelectronics STM32F7 Series Device Support, Drivers and Examples" section, you can download version 2.12.0. From that description, I see they improved the functionality of the SPI code.
- Once you have that update installed, you can add the open the Manage RTE window:
http://www.keil.com/support/man/docs/uv4/uv4_ca_rtemanager.htm
- Expand the "CMSIS driver" software component, and check the box next to SPI. You might have to hit the resolve button on the bottom.
You can read about the SPI functions here:
http://www.keil.com/pack/doc/CMSIS/Driver/html/group__spi__interface__gr.html