Skip to main content
linas2
Associate III
February 10, 2013
Question

Bluetooth module echo problem

  • February 10, 2013
  • 11 replies
  • 2090 views
Posted on February 10, 2013 at 20:24

Hello, i am working on labview communication with bluetooth module driven by STM32F4, and some how i can't make it work.

I can easy send data to labview, but not other way around, i have no idea where problem is. If i short bluetooth module Rx Tx line, i get same data i send, so problem is with STM32F4 itself. I have high levels if i do nothing, so pullup is ok. code is from forum, but other codes from internet do same thing, can't make echo

// STM32 USART3 (Tx PB.10, Rx PB.11) STM32F4 Discovery - sourcer32@gmail.com
#include ''stm32f4xx.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* USART3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
/* GPIOB clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
}
/**************************************************************************************/
void USART3_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 9600 baud
- Word Length = 8 Bits
- Two Stop Bit
- Odd parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 9600;
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_Init(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
USART3_Configuration();
while(1)
{
uint16_t Data;
while(USART_GetITStatus(USART3, USART_IT_RXNE) == RESET); // Wait for Char
Data = USART_ReceiveData(USART3); // Collect Char
while(USART_GetITStatus(USART3, USART_IT_TXE) == RESET); // Wait for Empty
USART_SendData(USART3, Data); // Echo Char
}
while(1); // Don't want to exit
}

Bluetooth module is cheap one from ebay BT_Module v1.2 Processor is clocked at 168MHz from 8MHz crystal #dte #null-modem #dce
    This topic has been closed for replies.

    11 replies

    Tesla DeLorean
    Guru
    February 10, 2013
    Posted on February 10, 2013 at 23:32

    Perhaps you have the Rx/Tx wired backward? Provide a schematic of your circuit, and links to BT module datasheet/manual.

    Does the STM32F4 serial port loop back properly if you test that?

    If you have built the project from scratch ensure that HSE_VALUE is consistent with the 8 MHz crystal.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    linas2
    linas2Author
    Associate III
    February 11, 2013
    Posted on February 11, 2013 at 06:54

    Yes, HSE is 8MHz set in system_stm32f4.c file.

    Datasheet can be found here:

    http://apirola.files.wordpress.com/2012/11/hc-serial-bluetooth-products-201104.pdf

    I didn't test loop back on STM32F4 since i don't have lcd, but i will try that just by sending bunch of data and ending in one of the loop if data is same.

    Wires are ok, Rx go to Tx, and Tx go to Rx as usual

    Tesla DeLorean
    Guru
    February 11, 2013
    Posted on February 11, 2013 at 13:10

    Could you use a debugger, or secondary serial port?

    I think you're going to need a scope and work through the problem.
    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    Andrew Neil
    Super User
    February 11, 2013
    Posted on February 11, 2013 at 15:21

    ''Wires are ok, Rx go to Tx, and Tx go to Rx as usual''

    That would be usual for a DTE-to-DTE connection (aka null-modem).

    But your Bluetooth module should be a DCE; so its ''Tx'' should be an input - it is the data to be transmitted.

    Check the documentation

    very

    carefully to see which pin is ''in'' and which is ''out''

        
    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    linas2
    linas2Author
    Associate III
    February 11, 2013
    Posted on February 11, 2013 at 16:06

    Connection looks like good, since i can send data to Labview, but not other way around.

    I hang in while loop for flag checking

    Tesla DeLorean
    Guru
    February 11, 2013
    Posted on February 11, 2013 at 16:17

    And you can see inbound data on PB11 on a scope/analyzer? And it looks valid?

    I'm not sure what your expectations are here? Assume that the STM32F4 isn't going to register valid data if it doesn't see any. Try using a terminal app like RealTerm or TeraTerm, not LabView, make sure there are no flow control issues. Don't enable interrupts when you don't use a handler.

    // STM32 USART3 (Tx PB.10, Rx PB.11) STM32F4 Discovery - sourcer32@gmail.com
    #include ''stm32f4_discovery.h''
    /**************************************************************************************/
    void RCC_Configuration(void)
    {
    /* --------------------------- System Clocks Configuration -----------------*/
    /* USART3 clock enable */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
    /* GPIOB clock enable */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
    }
    /**************************************************************************************/
    void GPIO_Configuration(void)
    {
    GPIO_InitTypeDef GPIO_InitStructure;
    /*-------------------------- GPIO Configuration ----------------------------*/
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    /* Connect USART pins to AF */
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
    }
    /**************************************************************************************/
    void USART3_Configuration(void)
    {
    USART_InitTypeDef USART_InitStructure;
    /* USARTx configuration ------------------------------------------------------*/
    /* USARTx configured as follow:
    - BaudRate = 9600 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 = 9600;
    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_Init(USART3, &USART_InitStructure);
    USART_Cmd(USART3, ENABLE);
    }
    /**************************************************************************************/
    int main(void)
    {
    RCC_Configuration();
    GPIO_Configuration();
    USART3_Configuration();
    while(1)
    {
    uint16_t Data;
    while(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET); // Wait for Char
    Data = USART_ReceiveData(USART3); // Collect Char
    while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); // Wait for Empty
    USART_SendData(USART3, Data); // Echo Char
    }
    while(1); // Don't want to exit
    }

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    linas2
    linas2Author
    Associate III
    March 3, 2013
    Posted on March 03, 2013 at 11:38

    every thing was right, except flag checking was wrong

    while(USART_GetITStatus(USART1, USART_IT_RXNE)==RESET);
    data=USART_ReceiveData(USART1);
    while (USART_GetITStatus(USART1, USART_IT_TXE) != RESET);
    USART_SendData(USART1, (uint8_t) data);
     I used other UART and other pins, since i try almost all UART in this mcu, now it works as it should.
     If some one needs example how to communicate with labview to get data from mcu and vice versa ,i can post vi and code, it works very well 
    

    bee2
    Associate III
    April 9, 2013
    Posted on April 09, 2013 at 23:09

    Hi Kilohercas, I wouldn't mind the VI if thats ok. I'm working on a similar project -> STM32F4 discovery board, RN-41 BT module and Labview. Using the discovery board and BT module I can communicate with hyperterminal and can send andreceivedata fine (thanks to some advice from Clive1). I'm having trouble receiving data from the discovery board back to Labview, I get an error (1073807298 I/O error). I use the basic serial read/write example to send a value of '1' to request a data array. Using the Uvision debugger I see the '1' arrive, the interrupt then runs and by putting a break point after the USART_SendData function, which the program reaches, I assume the processor is sending the data array back but the error flags up??? I have attached screen shot of Labview front panel with error and UVision showing the IRQhandler with program stopped at break point, which might better explain my problem.

    If I do short the RX/TX on BT module I don't get the data back that I'm sending so I'm sure issue is with Labview.

    The problem seems to be with the BT module as I can do a loop back test using Labview and a serial cable, but I can also loop back with hyperterminal and the BT module....puzzled???

    ________________

    Attachments :

    comms_error.JPG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzzI&d=%2Fa%2F0X0000000bT5%2FeHuR7fWiNk2oQAHe67ulDj5NruksdoIX6SM4Me9RZcU&asPdf=false
    bee2
    Associate III
    April 13, 2013
    Posted on April 13, 2013 at 17:06

    problem was sorted using info at this link

    http://digital.ni.com/public.nsf/allkb/60DDFED7EFEFE7188625705700750821?OpenDocument

    linas2
    linas2Author
    Associate III
    April 14, 2013
    Posted on April 14, 2013 at 21:49

    i don't use VISA, i use blue-tooth functions. it even start to search bluetooth module, and do all good stuff. change just address of device (you can found it in device section)

    ________________

    Attachments :

    X-Ray_UART.vi : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I04U&d=%2Fa%2F0X0000000bT4%2FIQsgpCO.eZRfbTqQs.SbdDHUjhEXpKJ8aqucOENDzuI&asPdf=false