AnsweredAssumed Answered

USART communication INEMO- STM32F4

Question asked by sinatra.baldassare on May 2, 2015
Good morning guys. I'm writing because I need help for interfacing an Inemo M1 with a STM32F4. I have the need to take all the sensor values of  Inemo on  F4 via USART. I used to start the sample code of  'Inemo called "AHRS_LIB_Continuos" and I implemented a small library for port configuration USART1 that I post below:

#include "inemo_usart_interface.h"
#include "iNemo_Led.h"


/* PIN on J12 equal to Tx 6 (GPIOA9) e Rx 7 (GPIOA10)*/


FlagStatus xUsartTxComplete;
FlagStatus xUsartRxComplete;


void usart1_IRQHandler(void);


ErrorStatus usart_initialize() {
  


  USART_InitTypeDef usart_init;
  NVIC_InitTypeDef NVIC_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
  
  /*Enable usart periph clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE);
  
  /* Configure and enable usart1 interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_Init(&NVIC_InitStructure);
  
  /* Configure usart pins: RX and TX ---------------------------------*/
  /* Configure MISO pin as Alternate Function Push Pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  
  /* Init usart */  
  usart_init.USART_BaudRate = 512000;
  usart_init.USART_WordLength = USART_WordLength_8b   ; 
  usart_init.USART_StopBits = USART_StopBits_1;
  usart_init.USART_Parity = USART_Parity_No;
  usart_init.USART_Mode = USART_Mode_Rx;
  usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_Init(USART1, &usart_init);
  
  USART_Cmd(USART1, ENABLE);
  
  USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
  USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
  xUsartRxComplete = USART_GetFlagStatus(USART1, USART_IT_RXNE);
  xUsartTxComplete = USART_GetFlagStatus(USART1, USART_IT_TXE);
  iNEMO_Led_Toggle(LED1);
  return SUCCESS;


}

void usart_raw_receive(uint8_t *data, uint16_t length) {
  
  uint16_t i;
  uint8_t rxbyte;
  
  for(i=0; i<length; i++) {
    rxbyte = USART_ReceiveData(USART1);
    data[i] = rxbyte;
    while(xUsartRxComplete != SET);
    xUsartRxComplete = RESET;
  }
  
//  if(data[0] == 0xAA){iNEMO_Led_Toggle(LED1);};
}


void USART1_IRQHandler(void) {
  if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET) {
    xUsartTxComplete = SET;
    USART_ClearITPendingBit(USART1, USART_IT_TXE);
  } else if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) {
    xUsartRxComplete = SET;
    USART_ClearITPendingBit(USART1, USART_IT_RXNE);
  }
}
  


Given that the transmission from the F4 working properly, because already tested, I need to run the rx and tx on 'Inemo. Do you believe that I have to change something in the example code (for example vector table or other things ) and in my library? In particular in this case I'm trying to send a byte from F4 to inemo to test the communication, but it doesn' t work.


Thank you. I await answers.

Outcomes