0

I have done some research but couldn't find a fitting solution for my problem. As I am really out of any idea now, as well what I should search for, as how to fix the problem myself, I want to ask you.

As I am new to C, I hope it's not too much of a stupid beginner's question, but I really don't know how to fix it.

While trying to get it going, I delimited the problem to the following code:

uint32_t possibleBaudrates[12] =
        {
            1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600, 1382400
        };
uint8_t AT[2] = {'A', 'T'};

for(uint8_t i = 0; i < 12; ++i)
{
    UART_SetBaudrate(&UART_0, possibleBaudrates[i], 16);

    delay(1000000);

    UART_Transmit(&UART_0, AT, 2);
}    

To give you some more information, I am trying to configure the Baudrate of a HC06 module. To test this, I am sending AT to Blueterm on my smartphone. The problem should be the array, because the following code is working well (it writes 12x AT on Blueterm on my Smartphone):

uint32_t possibleBaudrates[12] =
        {
            1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600, 1382400
        };
uint8_t AT[2] = {'A', 'T'};

for(uint8_t i = 0; i < 12; ++i)
{
    UART_SetBaudrate(&UART_0, 9600, 16);

    delay(1000000);

    UART_Transmit(&UART_0, AT, 2);
}

What I expect in the first code is a single AT on Blueterm, but I did at least one mistake.

Edit: I think i gave too less information, sry. The behaviour of the first code example is, that nothing is print on Blueterm. It should be, "AT" once (The Baudrate of the HC06 Module is set to 9600 and if it goes through the array, it should one be at 9600)

Edit2: Its only the problematic section, later on it is supposed to have the use that you can get the Baudrate, set on the HC06 Module (If I am not connected to Blueterm, "AT" makes the Module to answer with "OK". But going through the array seems to go wrong.) Additionally to mention, if the Baudrate is not 9600 there is nothing printed on Blueterm (tested)

Edit3: I have to apologize, with the hint of Rad Lexus i found another problem with my code (seems to be a misunderstanding of the UART_SetBaudrate Method of Dave4, seems to set after using it once, so

UART_SetBaudrate(&UART_0, 2400, 16);
delay(10000000);
UART_Transmit(&UART_0, AT, 2);
UART_SetBaudrate(&UART_0, 9600, 16);
delay(10000000);
UART_Transmit(&UART_0, AT, 2);
UART_SetBaudrate(&UART_0, 9600, 16);
delay(10000000);
UART_Transmit(&UART_0, AT, 2);

wont print anything on blueterm, while

UART_SetBaudrate(&UART_0, 9400, 16);
delay(10000000);
UART_Transmit(&UART_0, AT, 2);
UART_SetBaudrate(&UART_0, 2400, 16);
delay(10000000);
UART_Transmit(&UART_0, AT, 2);
UART_SetBaudrate(&UART_0, 4800, 16);
delay(10000000);
UART_Transmit(&UART_0, AT, 2);

will print 3x "AT" on blueterm

Thx in advance, I now know how to go on (where to look after the mistake) and sry for the misleading question.

Do I have to Finish this Question now or Delete or whatever?

6
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behaviour, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example. Commented May 14, 2016 at 12:52
  • Did you try using other values than 9600 for your test ? Commented May 14, 2016 at 12:54
  • i dont know how to edit my question, sry. To make the behaviour clear, it doesnt print anything on Blueterm if I execute the first code example. But as shown, the second Code example is printing 12x "AT" on Blueterm (it should print it if the Baudrate is 9600) Commented May 14, 2016 at 12:56
  • "Did you try using other values than 9600 for your test ?" 9600 is the Baudrate of the HC06 Module, only and everytime if the Uart Baudrate is set to 9600 too, it should print AT Commented May 14, 2016 at 12:57
  • What library or SDK are you using? Maybe the function returns a result ("fail/success") or sets some error flag. Commented May 14, 2016 at 13:08

1 Answer 1

2

So, correct me if I'm wrong. You want to do a cycle and try to send a message with every possible baud rate, right?

If that's so, you will recieve garbage characters at the terminal each time you transmit in a baudrate that's not the terminal's baud.

You should either set the program to work at a given baudrate or select the baudrate in which you want to work at the beginning of the program.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.