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

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 &

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; //

while(SPI3->SR & SPI_SR_RXNE){} // Tiempo de espera mientras se vacia el buffer

recibido=SPI3->DR;

}

char leer_datos(char direccion){

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 puede

SPI3->DR=direccion; //

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

SPI3->DR=0x00; //

while(SPI3->SR & SPI_SR_RXNE){} // Tiempo de espera mientras se vacia el buffer

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){

}

// *******************************************************

}

// ***********************************************************

Parents
  • It is common that you cannot read-back a Tx register:

    These are not memory locations, they are "gateways" into the hardware:

    • When you write, you send stuff to the transmitter;
    • When you read, you receive stuff from the receiver.

    As   said, you need to study the datasheet to understand how this works in your particular chip.

    the proof is the debugger

    No. 

    The proof is to use an oscilloscope or analyser to see what is actually happening on the actual hardware lines.

Reply
  • It is common that you cannot read-back a Tx register:

    These are not memory locations, they are "gateways" into the hardware:

    • When you write, you send stuff to the transmitter;
    • When you read, you receive stuff from the receiver.

    As   said, you need to study the datasheet to understand how this works in your particular chip.

    the proof is the debugger

    No. 

    The proof is to use an oscilloscope or analyser to see what is actually happening on the actual hardware lines.

Children
No data