Author Topic: Uart speed problem  (Read 5813 times)

0 Members and 1 Guest are viewing this topic.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Uart speed problem
« on: April 04, 2011, 12:45:42 PM »
Hi,

I have this bluetooth module ( http://www.elechouse.com/elechouse/index.php?main_page=product_info&cPath=&products_id=647 ) but when I was changing the speed to a higher value I screwed up and set the baud rate to 1382400. I was using a USB to ttl uart bridge that uses the same chip as the axon 2 to set it up. I own an axon 2 too and I was using the bluetooth module to communicate with my pc and phone but now I cant do anything since none of my serial devices can work at such a rate and now I cant reconfigure it to a slower rate so I can use it again. It was a noob mistake I know can someone help me? How can I connect to it, what do I need to connect to it? Can an axon 2 uart work at such a rate so maybe I can make a program in the axon to set the bluetooth?

Thanks in advance

Offline rbtying

  • Supreme Robot
  • *****
  • Posts: 452
  • Helpful? 31
Re: Uart speed problem
« Reply #1 on: April 04, 2011, 02:56:35 PM »
The Axon2 clock rate isn't fast enough to support that kind of a baud rate.  The website you linked mentions a USB connection on it - perhaps you could try to wire that up and set it from there.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #2 on: April 04, 2011, 03:30:00 PM »
I already wired it but I dont know how to use it... I just hooked it up to the pc and it didn't get recognised. It is powered by 3.3V and to use it with usb I powered it with axon and plug the data wires to a usb cable to the pc (with shared ground) is there anything else that uses that speed so I can salvage my module?

Thanks for the heads up about the axon speed.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #3 on: April 05, 2011, 01:03:08 AM »
I searched all around and couldn't find anything wired that uses that baud rate. The only alternative that i found ir to use ao mcu to do it por me. What would be the cheapest mcu capable me doing it? Please help me :p

Offline rbtying

  • Supreme Robot
  • *****
  • Posts: 452
  • Helpful? 31
Re: Uart speed problem
« Reply #4 on: April 05, 2011, 07:19:10 AM »
You might be able to do it if you had a hardware serial port on your computer.  Barring that, any microcontroller capable of that kind of USART baud rate with any regularity would probably cost more (in time, if not money) than just buying a new module. 

On another note, have you tried going from 9600baud upward to see if it might have reset due to the unusual baud rate?  If it did, you may still be able to recover it.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #5 on: April 05, 2011, 08:04:35 AM »
I wouldnt mind spending some money in a new mcu since I was thinking of getting one anyway. But I need to know a good (cheapest) one that can support that baud. I have an hardware serial port but im pretty sure it cant support that baud rate either. Can someone point out any device or mcu that can handle it?

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Uart speed problem
« Reply #6 on: April 05, 2011, 09:16:22 PM »
Quote
baud rate to 1382400
As in 1.3824MHz?

You'll have trouble getting a UART to work at that rate. You might just make it with an AVR UART in double speed mode if you have a crystal an exact multiple of the freq you need. ie 8 x 1.3824

Surely there's a way to hard reset the gadget.
Scattered showers my arse -- Noah, 2348BC.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #7 on: April 06, 2011, 01:31:37 AM »
How would I set that up? I read somewhere that there is no way of hard reseting it and advising not to set that up in a baud rate higher than 115200 because it wouldn't be possible to send commands to it via pc again it would have to be via an mcu... I guess the pc can't reach that kind of speeds in a uart by normal means neither by my usb adapter.

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Uart speed problem
« Reply #8 on: April 06, 2011, 02:23:26 AM »
I would see two ways to do this.

a) get an 11.0592MHz crystal and use it with an AVR processor. Set the UART appropriately and send characters. The xtal is critical for this, it has to be 8x the frequency you need because the UART does a /8 to get the baud rate.

b) bit bang the data. If you just need a 0xAA or something for the gadget to read the bit rate from you can easily bit bang this out a pin yourself. For that matter you can bit bang any number of bytes.

What data do you need to reset the baud rate?

______
Rob
Scattered showers my arse -- Noah, 2348BC.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #9 on: April 06, 2011, 04:54:11 AM »
I need to send an AT command: "AT+ORGL\r\n" I think thats it. To reset it to default. I think its stupid it doesn't have an hard reset though... Anyway how would I send it then?

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Uart speed problem
« Reply #10 on: April 06, 2011, 05:44:01 AM »
You should be able to write a simple bit bang function to send serial data out a pin. Here is a test app I wrote soem time ago.

Code: [Select]
void debug_serout_IO (unsigned int val) {
int nbits;

val <<= 1; // create a start bit in the data

asm("sbi 0x18,0");  // ensure TX is high

for (nbits = 0; nbits < 9; nbits++) {
if ((val & 0x01) == 0x01) // test LSB hi/lo
asm("sbi 0x18,0"); // set/clear PORTB:0 according
else // to the bit level of the LSB
asm("cbi 0x18,0");
delay ();
val >>= 1;
}
asm("sbi 0x18,0");  // ensure TX is high
delay (); // stop bit

}

I can't remember how fast it runs or even what AVR chip it is written for but it should transmit a character serially out a pin. Also note that I've modified it to more suite what you need but have not tested.

The "delay()" should be something that causes the bit time to be correct.

The address 0x18 is PORTB on the chip I was using, you will probably have to change this.

You can have a loop that scans the AT string and sends the bytes by calling this function.

I think there is no way you will get this working without a scope or logic analyser though.

______
Rob

« Last Edit: April 06, 2011, 05:46:05 AM by Graynomad »
Scattered showers my arse -- Noah, 2348BC.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #11 on: April 06, 2011, 06:03:35 AM »
Many thanks!

I'll try it later on. I'll try to hook it up directly :P I am using an ATmega640 (Axon2).

Should I give a character directly to that function and it will transmit it like serial? And will it work well with a string, will it be the same? And one more thing how do I define which pin is going to output it?
Should I try to make a soft uart with that rate using the webbotlib instead of that?

I'm sorry, I'm not a very experienced programmer.


Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Uart speed problem
« Reply #12 on: April 06, 2011, 06:29:42 AM »
Quote
Should I give a character directly to that function and it will transmit it like serial?
Correct.

Quote
And will it work well with a string, will it be the same?
If you add a loop to scan the string.

Quote
And one more thing how do I define which pin is going to output it?
in the statement

xxx  0x18,1

the 0x18 is a port address and the 1 is the bit number.

If you choose a convenient pin I can probably look at the 640 data sheet and come up with the right numbers.

Quote
Should I try to make a soft uart with that rate using the webbotlib instead of that?
That's a better option IF it can go fast enough. Most generic software UARTs are too slow I think but I'm not familiar with the Webbotlib code.

BTW I think the code was for the GCC compiler, asm("") may not work with what you are using, but there will be an equivelant, for example

PORTB != (1 << BIT_NUM)

Is more portable and should work with most compilers. See how it goes.

______
Rob


Scattered showers my arse -- Noah, 2348BC.

Offline MikeK

  • Full Member
  • ***
  • Posts: 97
  • Helpful? 5
Re: Uart speed problem
« Reply #13 on: April 06, 2011, 04:05:25 PM »
According to the "AT command" manual for that device you boot it up by holding one pin high while applying power and you then communicate with it at 38400 baud.  Are you saying this is not the case?  Seems odd that someone would create a device that didn't have a stable config mode interface.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #14 on: April 07, 2011, 06:55:37 AM »
Seems odd that someone would create a device that didn't have a stable config mode interface.

Yes it is odd and stupid but it is true...

I was going to make a soft uart but in the webbotlib he says that they are very slow and we shoudn't expect a faster rate than 9600 lol so I didn't bother to do it. I'll try your way Graynomad just need to look at the processor datasheet to get the address of a pin. The function you sent me compiles as is so ill make the loop and try. Thanks

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Uart speed problem
« Reply #15 on: April 07, 2011, 07:16:08 AM »
If you get it working just run a tight loop with a known character (0x55 or 0xaa are always good) and check with a scope or LA to get the bit rate right.

Then try your AT string and verify that looks good.

ONLY THEN hook up to the device.

If you connect to the thing before you are 100% sure the data is correct you could make it worse, at least now you seem to know what the data rate should be.

______
Rob
 
Scattered showers my arse -- Noah, 2348BC.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #16 on: April 07, 2011, 09:52:43 AM »
How can i check if the data is coming out right? And first of all how can I know the address of a pin(sorry for the noob question)
« Last Edit: April 07, 2011, 10:08:03 AM by Dothos »

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Uart speed problem
« Reply #17 on: April 07, 2011, 10:21:38 AM »
Quote
How can i check if the data is coming out right?
You will need instruments, either a scope or logic analyser. I can think of no way verify the output without one or the other.

Quote
And first of all how can I know the address of a pin
Look at the schematic and choose a pin, make a note of what it is, say PB0, then look in the mega640 datasheet for the address of PORTB. Check "register summery" (section 33) near the bottom of the document. For example on the 640 I think you'll find PORTB at 0x05.
 

______
Rob
« Last Edit: April 07, 2011, 10:28:27 AM by Graynomad »
Scattered showers my arse -- Noah, 2348BC.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #18 on: April 07, 2011, 01:19:14 PM »
I'm sorry but I should put what in the pin address? 0x05? or is that an offset?

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Uart speed problem
« Reply #19 on: April 07, 2011, 08:41:54 PM »
On the 640 0x05 is the address of PORTB, so

asm("cbi 0x05, 1");

will "clear bit" 1 in PORTB. So if PORTB was 11111111 before the instruction it will be 11111101 after.

If we look at the Axon schematics we see that PB0 is also the SS so this might be a good a choice as any pin.

As I said though without instruments to check the output this is all moot.

______
Rob
Scattered showers my arse -- Noah, 2348BC.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #20 on: April 10, 2011, 04:49:50 PM »
I coudn't try it yet because I had very little time and need an osciloscope to teste the speed, ill do it tomorrow in the university I atend to. I just want to know how I ajust the speed. I supose is the delay but how much to I delay and there are 2 delays are they going to wait the same time?

BTW I got it to output through pin A0. I set the delay to 1sec and used a multimeter.
« Last Edit: April 10, 2011, 05:07:28 PM by Dothos »

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Uart speed problem
« Reply #21 on: April 10, 2011, 07:02:09 PM »
At this speed "delay()" may be just a few instructions.

I would replace it with

for (int x = 0; x < 10; x++){};

to start with then see what the speed is.

Quote
there are 2 delays are they going to wait the same time?
The first one (inside the loop) is the critical one as that determines the bit times.

The second one is just a stop bit and it can be as long as you like but normally a single bit time as well. Because the second one doesn't have the loop overhead it probably should be a little bit longer, say x < 15, but I'd just make it 2x the first one, that extra time won't do any harm.

______
Rob

« Last Edit: April 10, 2011, 07:03:58 PM by Graynomad »
Scattered showers my arse -- Noah, 2348BC.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #22 on: April 11, 2011, 02:33:17 AM »
I guess I'll try to send something out a uart at lower speed measure it and try to replicate the speed until I can get your funtion to be recognisedby another uart. Then decrease the time until I get the frequency I need.

Many thanks for your help

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #23 on: April 11, 2011, 05:22:54 PM »
I cant seem to get a valid signal to out put the way you told me. The problem is most probably me, I must be doing something wrong.

When I short the rx and tx on the bluetooth dongle and connect through bluetooth I can get a reading back from the bluetooth. I was thinking.. what if I write a simple routine that stores the signal in the memory I replay it back? I would just have to change the wires and click a button. I'm not very optimistic but it's worth a shot. :p

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Uart speed problem
« Reply #24 on: April 11, 2011, 07:47:10 PM »
Quote
I cant seem to get a valid signal
Are you looking at the output with a scope? If so what do you see?

The above routine should be close but I admit it can be hard to get these things working without good test equipment and evey harder to debug remotely.


Quote
When I short the rx and tx on the bluetooth dongle and connect through bluetooth I can get a reading back from the bluetooth
That actually sounds promising, you can use the BT module itself as a UART.

I'd say that's got a real good chance of working, unless there's some timing issues like it can't change the bit rate while transmitting characters or only works after powerup and before doing anything else etc.

If it doesn't work then another option may be to buy a second BT module and use that to send the data to the first one.
« Last Edit: April 11, 2011, 07:49:17 PM by Graynomad »
Scattered showers my arse -- Noah, 2348BC.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #25 on: April 12, 2011, 08:07:51 AM »
I woudn't mind bying a second bluetooth device but im afraid I'll have the same problem. That one is really cheap and im not willing to buy an expensive one do you know a good cheap one that have an reset or any other way to reconfigure it so I don't get stuck again?

I used an osciloscope but one I try to output something it stays steadly in 5V. i'll send you the modifications I did so I can use pin A0 so you can check if I didn't mess anything up.


uint32_t dl=10;

void debug_serout_IO (unsigned int val) {
    int nbits;
   
    val <<= 1; // create a start bit in the data
   
    asm("sbi 0x00,0");  // ensure TX is high

    for (nbits = 0; nbits < 9; nbits++) {
       if ((val & 0x01) == 0x01)    // test LSB hi/lo
          asm("sbi 0x00,0");       // set/clear PORTB:0 according
       else                   // to the bit level of the LSB
          asm("cbi 0x00,0");
      for (int x = 0; x < dl; x++){};
       val >>= 1;
    }
    asm("sbi 0x00,0");     // ensure TX is high
    for (int x = 0; x < dl/2; x++){}            // stop bit
}

I made some attempts and realised I don't know how to record the signal. :p

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Uart speed problem
« Reply #26 on: April 12, 2011, 08:45:23 AM »
By "A0" I guess you mean PORTA bit 0.

If so the address for PORTA is 0x02, not 0x00.

So change the sbi and cbi instructions to use 0x02.

Did you get the mega640 data sheet and have a look at the register summary? All the addresses are there. 

Another thing you have to do is set that pin to an output by writing a 1 to the data direction register (DDR) for PORTA

  asm("out 0x01, 1");

or

  DDRA = 1; // if DDRA has been defined on your system

This only needs doing once at the start of your program.

______
Rob


Scattered showers my arse -- Noah, 2348BC.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Uart speed problem
« Reply #27 on: April 14, 2011, 07:00:51 AM »
I have not been able to use the scope again to check if it is working ok now and fine tune the timings.

I am going to create a thread with a proper name so I can get someone to tell me where to get a bluetooth that can get to that baud rate and be set back into a slower one without problems.
In the meanwhile i'll try to get your solution to work ;)

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Uart speed problem
« Reply #28 on: April 14, 2011, 09:55:05 AM »

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Uart speed problem
« Reply #29 on: April 14, 2011, 11:02:46 AM »
Ok I had a go with the code on a 16MHz Arduino. The C version can only get to 550kHz, bummer, I thought it would do better.

It could be speeded up but not enough so I wrote a version in assembler, that can do 4Mhz or 1.6Mhz (see attached for 1.6 version) but there isn't enough resolution to get the 1.382400 you need.

However if you swap the crystal for a 1.382400 version it should be bang on.

______
Rob
« Last Edit: April 14, 2011, 11:04:26 AM by Graynomad »
Scattered showers my arse -- Noah, 2348BC.

 


Get Your Ad Here