cancel
Showing results for 
Search instead for 
Did you mean: 

STM32vldiscovery and bt module

joesoftware
Associate II
Posted on December 21, 2012 at 00:41

Hi i want to connect my stm32vldiscovery with HC05 Bluetooth module, the communication is uart and this HC05 need to have only3.3V on uart_tx and uart_rx, can i connect directly on uart port of stm32vldiscovery? or i need a resistor i don't know if stm32vldiscovery uart port works on 5v or 3.3v.

Someone can help me?

Thanks
7 REPLIES 7
Posted on December 21, 2012 at 01:34

Most of the DISCOVERY boards have a 3V regulator supplying the primary voltage, PA9/10 for USART1 are 5V tolerant (FT) pins which means they can accept an input of up to 5V without injecting that into the IO rail. Now clearly you shouldn't be driving a 3V PP output against a 5V supply, but you could use an OD output and pull that to 5V. The output will nominally be the primary supply to the part, in this case 3V (assume VIL,VIH,VOL,VOH levels accordingly)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Evangelist
Posted on December 21, 2012 at 07:37

''i don't know if stm32vldiscovery uart port works on 5v or 3.3v''

So look at the boardschematic - it's in the User Guide.

Also, study the chipdatasheet for IO pin characteristics...
joesoftware
Associate II
Posted on December 21, 2012 at 22:42

Thanks, i connect pin to pin stm32vldiscovery and hc06 module, from pc i see new device called Linvor, and i can join him.

Now next step for me is write a driver for send and receive data from pc to board with bt. I used PA2 and PA3 pin that is usart2_TX and usart2_RX, and i configured usart in this way,

<
FONT
lang
=
JA
face
=
CMR12
> 
<
P
align
=
left
>USART InitTypeDef USART InitStructure ;</
P
> 
<
P
align
=
left
>USART InitStructure .USART BaudRate = 9600;</
P
> 
<
P
align
=
left
>USART InitStructure .USART WordLength = USART WordLength 8b ;</
P
> 
<
P
align
=
left
>USART InitStructure . USART StopBits = USART StopBits 1 ;</
P
> 
<
P
align
=
left
>USART InitStructure . USART Parity = USART Parity No ;</
P
> 
<
P
align
=
left
>USART InitStructure . USART HardwareFlowControl=</
P
> 
<
P
align
=
left
>=USART HardwareFlowControl None ;</
P
> 
<
P
align
=
left
>USART InitStructure .USART Mode = USART Mode Rx </
FONT
><
FONT
lang
=
JA
face
=
CMSY10
>|</
P
></
FONT
><
FONT
lang
=
JA
face
=
CMR12
> 
<
P
>USART Mode Tx ;</
P
></
FONT
>

What else doi need to configure? where can isee the data arrived and how can i send my data to usart?

Someone have done something like this? Thanks for the help.
Posted on December 22, 2012 at 04:11

USART1 looks a bit like this

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/USART%20simulator%20STM32f1xx%20discovery&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=312]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FUSART%20simulator%20STM32f1xx%20discovery&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=312

You'll need to tweak the USART and pins appropriately.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
joesoftware
Associate II
Posted on December 22, 2012 at 19:10

i changed code in this way:

// STM32 USART2 (Tx PA.2, Rx PA.3) - STM32 VLDiscovery - sourcer32@gmail.com 
#include ''stm32F10x.h'' 
#include ''STM32vldiscovery.h'' 
/**************************************************************************************/ 
void RCC_Configuration(void); 
void GPIO_Configuration(void); 
void USART_Configuration(void); 
/**************************************************************************************/ 
int main(void) 
{ 
RCC_Configuration(); 
GPIO_Configuration(); 
USART_Configuration(); 
while(1) 
{ 
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Wait for Empty 
USART_SendData(USART2, 0x49); // Send 'I' 
} 
while(1); // Don't want to exit 
} 
/**************************************************************************************/ 
void RCC_Configuration(void) 
{ 
// clock for GPIO 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); 
/* Enable UART clock */ 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); 
} 
/**************************************************************************************/ 
void GPIO_Configuration(void) 
{ 
GPIO_InitTypeDef GPIO_InitStructure; 
/* Configure USART Tx as alternate function push-pull */ 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // PA.02 USART1.TX 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
GPIO_Init(GPIOA, &GPIO_InitStructure); 
/* Configure USART Rx as input floating */ 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // PA.3 USART1.RX 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 
GPIO_Init(GPIOA, &GPIO_InitStructure); 
} 
/**************************************************************************************/ 
void USART_Configuration(void) 
{ 
USART_InitTypeDef USART_InitStructure; 
/* USART configured as follow: 
- BaudRate = 115200 baud 
- Word Length = 8 Bits 
- One Stop Bit 
- No parity 
- Hardware flow control disabled (RTS and CTS signals) 
- Receive and transmit enabled 
*/ 
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_None; 
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; 
/* USART configuration */ 
USART_Init(USART2, &USART_InitStructure); 
/* Enable the USART1 */ 
USART_Cmd(USART2, ENABLE); 
} 
/**************************************************************************************/
 i connect docklight on serial port com 18 (the port of linvor device) but nothing is receive in the pc. Is something wrong in this code? How can i save data arrived in stm32vldiscovery from usart2?
 Thanks

Posted on December 22, 2012 at 23:19

To poll the USART

    while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET); // Wait for Not Empty

    

    x = USART_ReceiveData(USART2);

You should perhaps review the interrupt examples in the firmware libraries.

The USART pins of the STM32 are not electrically compatible with PC serial ports. You will need a RS232 level shifter, or use a CMOS Serial to USB type device.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
joesoftware
Associate II
Posted on December 23, 2012 at 10:12

i'm using for this my bt modules, but it doesn't work good at this moment.

No data arrive in stm32vldiscovery from bt modules and no data arrive to pc from bt.... i think there is something wrong in my configuration, cause modules works good in other Platform i tried with arduino, then is only a configuration problem, thanks for the help, and i hope in some other idea to fix it.

EDIT

Fixed the problem was an bad electrical connection from modules to board