cancel
Showing results for 
Search instead for 
Did you mean: 

Hello , I am trying to read address from GP30 using spi as an interface between stm32l476RC and to transfer it to pc via UART, there is no errors , i have reversed the programmer using Cube Programme but I am not able to see data sent .please help

Douma.1
Associate II

int main(void)

{

 /* USER CODE BEGIN 1 */

  uint8_t read_opcode ;

  uint8_t read_addr ;

  uint8_t Result_read = 0x00;

  uint8_t Result_read_buff=0x00;

  char*commande;

  commande = (unsigned char *) 0x5A;

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_SPI1_Init();

 MX_USART2_UART_Init();

 /* USER CODE BEGIN 2 */

  

  

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4, GPIO_PIN_SET);

HAL_Delay(10);

//Read Data

//1.PUT CS LOW 

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);

//2.Transmit Register Adresse!

HAL_SPI_Transmit(&hspi1,&read_opcode,1,100);

HAL_SPI_Transmit(&hspi1,&read_addr,1,100);

//3.Read

HAL_SPI_Receive(&hspi1,&Result_read_buff,1,100);

Result_read |= (Result_read_buff);

return Result_read;

//Bring CS High-Desactivation

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);

//UART_Communication

commande ="RC_RAA_RD";

HAL_UART_Receive(&huart2,commande,10,1700);

HAL_UART_Transmit(&huart2,&Result_read, 8, 1700);

2 REPLIES 2
TDK
Guru

> return Result_read;

Never return from main. It's unclear why this statement is in there.

> char*commande;

>  commande = (unsigned char *) 0x5A;

> HAL_UART_Receive(&huart2,commande,10,1700);

You're writing 10 bytes to address 0x5A here, which is unlikely what you want. Define it as an array of length 10+ if you want to receive 10 bytes of data.

>  uint8_t Result_read = 0x00;

> HAL_UART_Transmit(&huart2,&Result_read, 8, 1700);

Sending 8 bytes when the variable is only 1 long doesn't make any sense.

These are basic C concepts. I would recommend brushing up on C pointers in general, or following existing SPI/UART example code.

If you feel a post has answered your question, please click "Accept as Solution".
Piranha
Chief II

There is no point in trying to "develop" firmware for MCU without understanding the basics of C programming. Start with this on a PC:

https://www.tutorialspoint.com/cprogramming/

https://www.cprogramming.com/tutorial/c-tutorial.html