cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Discovery UART problem using Rn-41 Bluetooth module

bee2
Associate II
Posted on March 21, 2013 at 08:24

I have the STM32F4 communicating with hyperterminal on windows 7 using a serial cable. My discovery board is plugged into an Embest expansion board which breaks out to an RS232 serial port and at the PC end I have a usb to serial converter as I have no serial port. I have gone back to the UART example Embest provide in their examples folder for the expansion board. All works fine hyperterminal receives the printf data.

I want to replace the serial cable with a Roving networks Rn-41-ms bluetooth device. I have fitted the Rn-41 to my board with a 3V supply and ground and I can talk to it via hyperterminal fine i.e can use get/set comands to confirm change settings on the device. I am using a bluetooth dongle at PC end.

My problem comes when trying to transmit from my program via the bluetooth device to hyperterminal. In the UART example COM1 is used for UART6 which is the serial port on the expansion board, so I have selected COM3 for UART1 which is shown STM32F4_discovery.h file. The way I have changed to COM3 is by basically changing all the COM1's in the main.c to COM3 but I've also enabled hardware flow control as this is required for the RN-41 device. The program compiles and downloads fine but no data is recieved by hyperterminal when run on the ST board?

I have set board rate, parity, stop bits etc the same on ST program, Rn-41 bluetooth device, PC bluetooth dongle and hyperterminal.

Any ideas or advice on other settings I should consider when changing com ports or debugging methods for UART appreciated, I don't have use of an oscilloscope until monday.

Expansion board

http://www.embest-tech.com/shop/product/dm-stf4bb-base-board.html

Bluetooth module

http://uk.farnell.com/jsp/displayProduct.jsp?sku=2144010&CMP=e-2072-00001000&gross_price=true&mckv=YKMwxwd8|pcrid|14164337469|plid|{placement}

#stm32f4 #rn-41 #bluetooth
23 REPLIES 23
Posted on March 21, 2013 at 15:03

The program compiles and downloads fine but...

This is a pretty low hurdle and doesn't speak to the functional correctness of the code.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
bee2
Associate II
Posted on March 21, 2013 at 16:49

Hi Clive1, I'm not to sure what you mean by your reply, I understand the fact the program compiles and downloads is no big deal, I was just giving as much info as I could or have I misunderstood you? Below is the main.c code from the example program I'm using, this has the code I've changed in related to the configuration of the UART (COM1 to COM3), I've just ordered a UART to RS232 converter so I can see if the data is actually being sent to the pins I'm using.

#include ''stm32f4xx.h''

#include ''stm32f4_discovery.h''

#include <stdio.h>

/** @addtogroup STM32F4xx_StdPeriph_Examples

  * @{

  */

/** @addtogroup USART_Printf

  * @{

  */ 

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

USART_InitTypeDef USART_InitStructure;

/* Private function prototypes -----------------------------------------------*/

#ifdef __GNUC__

  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf

     set to 'Yes') calls __io_putchar() */

  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)

#else

  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)

#endif /* __GNUC__ */

  

/* Private functions ---------------------------------------------------------*/

/**

  * @brief  Main program

  * @param  None

  * @retval None

  */

int main(void)

{

  USART_InitStructure.USART_BaudRate = 115200;

  USART_InitStructure.USART_WordLength = USART_WordLength_8b;

  USART_InitStructure.USART_StopBits = USART_StopBits_1;

  USART_InitStructure.USART_Parity = USART_Parity_No;

  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS;

  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  STM_EVAL_COMInit(COM3, &USART_InitStructure);

while (1)

  {

  /* Output a message on Hyperterminal using printf function */

  printf(''*USART Printf Example\n\r'');

  

}

  

  while (1)

  {

    int ch;

    

    while (USART_GetFlagStatus(EVAL_COM3, USART_FLAG_RXNE) == RESET);

  

    ch = USART_ReceiveData(EVAL_COM3);

  

    printf(''%c'', ch&0xff);    

  }

}

/**

  * @brief  Retargets the C library printf function to the USART.

  * @param  None

  * @retval None

  */

PUTCHAR_PROTOTYPE

{

  /* Place your implementation of fputc here */

  /* e.g. write a character to the USART */

  USART_SendData(EVAL_COM3, (uint8_t) ch);

  /* Loop until the end of transmission */

  while (USART_GetFlagStatus(EVAL_COM3, USART_FLAG_TC) == RESET);

  return ch;

}

#ifdef  USE_FULL_ASSERT

/**

  * @brief  Reports the name of the source file and the source line number

  *         where the assert_param error has occurred.

  * @param  file: pointer to the source file name

  * @param  line: assert_param error line source number

  * @retval None

  */

void assert_failed(uint8_t* file, uint32_t line)

  /* User can add his own implementation to report the file name and line number,

     ex: printf(''Wrong parameters value: file %s on line %d\r\n'', file, line) */

  /* Infinite loop */

  while (1)

  {

  }

}

#endif

/**

  * @}

  */ 

/**

  * @}

  */ 

Posted on March 21, 2013 at 18:18

Ok, it expresses my long standing frustration with being asked about problems with code that isn't presented.

The salient code would be STM32F4_discovery.c and STM32F4_discovery.h which has support of the USART's. This is not from the standard release, as there is no USART support in them at all. If there is a problem with the USART configuration and function these would be the first place to look. You might want to attach those files, or cite a download link for the code being used.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on March 21, 2013 at 21:33

Note COMn is 2, then in stm32f4_discovery.c there is only support for 2 USARTs, and the initialization code assumes all USART use APB2 clocks.

Modified

/public/STe2ecommunities/mcu/Lists/STM32Discovery/Attachments/5321/stm32f4_discovery.c

/public/STe2ecommunities/mcu/Lists/STM32Discovery/Attachments/5321/stm32f4_discovery.h

________________

Attachments :

stm32f4_discovery.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hzl9&d=%2Fa%2F0X0000000bPr%2FCvZk.ASosI1sN.OCy7pNOGDaXbv5yFmf4LuVPyZUZFw&asPdf=false

stm32f4_discovery.h : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hznn&d=%2Fa%2F0X0000000bPq%2FPqmFmWbrMaGPPjDmw2DjFhzKodPYnD.7kzc_q1KKzN0&asPdf=false
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
bee2
Associate II
Posted on March 25, 2013 at 12:03

Hi Clive1, thanks for info/mods on code, I will update my progress on the project soon which might help others, cheers

bl
Associate II
Posted on March 27, 2013 at 11:35

Bluetooth connected to a USART is what I'm working on at the moment so +1 for interest in this discussion. 

bl
Associate II
Posted on March 28, 2013 at 11:42

So the USARTs are connected via AHB2 and APB1 (ext COM2 which is connected via APB2).

..or if you DMA them then there is just an APB between the DMA and the USART. 

Its taken a bit of digging to realize that there are two levels of bridges - more like a PC architecture than a uP!!
Posted on March 28, 2013 at 12:11

Hardware Buses, Peripheral Buses.

APB1 is for the slower peripherals, APB2 for the faster ones.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..