Author Topic: Bluetooth to uart super fast in axon 2 need help!!  (Read 6797 times)

0 Members and 1 Guest are viewing this topic.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Bluetooth to uart super fast in axon 2 need help!!
« on: April 14, 2011, 07:15:44 AM »
Hi guys I have a problem I used a bluetooth to ttl adapter to communicate via uart with my axon 2 but it was slow as default (9600b/s) so as a clever guy that I have I decided to put it at full throttle...the problem is that this means the uart is now 1382400b/s and the configuration is made through the uart and now I cant get anything to connect at such speed to speed it down. (it doesn't have a hard reset)

I already posted this in the forums so I could get some help to get it back but I'm almost losing faith and I want to know if anyone knows of a cheap device that can go that fast, it can be another bluetooth adapter but with an hard reset so I don't end up with another lost one.

The other thread: http://www.societyofrobots.com/robotforum/index.php?topic=13589.0
Device: http://www.elechouse.com/elechouse/index.php?main_page=product_info&cPath=90_177_91&products_id=647

I'm sorry if this is double posting...

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #1 on: April 14, 2011, 09:54:50 AM »
According to the manual, compatible bluetooth speeds are:
Quote
4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600, 1382400

See page 231 of the ATmega640 manual for a list of speeds at 16MHz. It says max speed is 1Mbps, which is why it's not working.

You might be able to get 230.4kbps to work, but the error rate is very high so it might not work. Chances are 115.2kbps is the fastest you'll get.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #2 on: April 14, 2011, 11:06:07 AM »
I know I can't do it normally via a uart but with the axon I was just wondering if it is possible just sending the command in another way or if you know of other devices that can reach such speeds so I can use one. I have a usb to ttl that uses the same IC has the axon and can do it either.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #3 on: April 14, 2011, 01:16:33 PM »
check the datasheets here:
http://www.sparkfun.com/categories/16?page=all

You might find one thats compatible at higher speeds.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #4 on: April 14, 2011, 01:50:45 PM »
I asked for help to know if anyone could help so I could spare my self to start reading all datasheets of every serial device there is. It's very rare I've searched a lot and I want a cheap thing at most the double I paid for mine. But I guess I have no luck. One mistake I'm not making again that's for sure :p

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #5 on: April 14, 2011, 04:15:56 PM »
The only sure fired way with an ATMega640 is with a clock speed of 11.0592MHz with the U2X register bit turned on, and a baud register UBRR=0 (see ATMega datasheet).

That would give you 1.3824 baud

The Axon is clocked at 16Mhz and you may not want to brick your Axon in the attempt!
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #6 on: April 14, 2011, 05:05:18 PM »
why changing the clock would brick? (sorry noob question, probably)

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #7 on: April 14, 2011, 05:43:41 PM »
why changing the clock would brick? (sorry noob question, probably)
All I meant is that since the Axon already has an external 16MHz crystal then you may have to play with various fuse like settings and/or replace the crystal to change it. Hard to say without a LOT more reading. And as a part of that process you may accidentally clobber the Axon. So it 'may' be possible but may not be worth the risk of a $100 Axon vs just buying a new Bluetooth,
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #8 on: April 14, 2011, 07:37:47 PM »
The only sure fired way with an ATMega640 is with a clock speed of 11.0592MHz with the U2X register bit turned on, and a baud register UBRR=0 (see ATMega datasheet).

That would give you 1.3824 baud

The Axon is clocked at 16Mhz and you may not want to brick your Axon in the attempt!
Good idea. Dothos, just replace the crystal (and maybe crystal caps), and it should give you the speed you want.

Quote
asked for help to know if anyone could help so I could spare my self to start reading all datasheets of every serial device there is.
It's either I read all the datasheets for *your* project, or you read them all :P
(I don't memorize datasheets lol)

You don't need to read the entire datasheet, just search for allowable baud rates. It'll take you about a minute for each.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #9 on: April 15, 2011, 04:45:30 AM »
Thanks a lot I'll just buy another one. I don't want to risk kill one of your sons admin.
Is there a way to delay the signal some seconds so I can get the bluetooth device config it self?(last hope)

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #10 on: April 15, 2011, 11:51:48 AM »
Is there a way to delay the signal some seconds so I can get the bluetooth device config it self?(last hope)
Its not a question of  'delaying' its because the achievable baud rates are directly linked to the crystal that is clocking the Axon. The Axon crystal is 16MHz meaning that it can generate 1,000,000 baud or 2,000,000 baud but nothing in between. I've certainly used the 1,000,000 baud successfully. But you need 1,382,400 baud. The closest available is 1,000,000 and so the error percentage is quite high so may not work. Obviously 2,000,000 will be even worse.

The other alternative is to simulate the uart in software. The WebbotLib software uart code wont be able to work at that high speed but I may be able to write a one off for you.

I'm willing to TRY and help out - but NO promises

Tell me exactly what character sequence you need to re-program the bluetooth to 9,600 baud (I dont have time to read the datasheet) and which Axon uart you will use to talk to it and whether you are using an Axon or Axon II (Axon II right?). I can then send you a hex file to try. It may work, or may not, but you wont be any worse off. I wont be able to test it since I don't want to sacrifice my own bluetooth in the process :P

If it works then I will of course own your soul  ;D ;D ;D


Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #11 on: April 15, 2011, 08:06:06 PM »
I said delay because connecting through bluetooth connecting tx and rx I can communicate (obviously) at that speed, from and to the adapter. If I can delay the signal some seconds I could send the command with the device put it in config mode and then receive the same signal it send. Or getting the axon to record the signal and then resend it.(I set off to try the later one myself but I'm not very proficient in programming and couldn't do anything usefull but you guys are pros).

I'm very thankfull for your help I'm using the axon 2 and the command is "AT+ORGL\r\n" (no quotes). I would rather use uart 3(just more space)  but any of the other 2 is fine with me or any other pin depending on the way you are thinking of implementing it  ;D

If you do it I'll gladly email my soul to you  :P

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #12 on: April 15, 2011, 10:46:06 PM »
@Webbot
I tried this in software on the original thread pertaining to this problem. The best I could get (using an ATmega328 @ 16MHz) was 4, 2.66, 2.00 and 1.6 MHz rates. Without changing the crystal to 18.3824MHz I'm pretty sure that's as good as can be got with software.

I'm happy to be proven wrong though if you share the code :)

With a change to an 11.0592 xtal the UART should do it according to the data sheet. But either way Dothos is faced with hacking his Axon.

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

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #13 on: April 16, 2011, 12:48:06 AM »
Jeez we're getting some mileage out of this. Here's another thought.

The UARTs can take an external clock, at least one of them (XCLK1, well it's got a label which implies it's used somewhere but the schematics are the typical unintelligible Eagle output so I can't really tell) is brought out to a header on the Axon. If this is so then an off-board oscillator could be rigged up, thus no Axon hacking.

______
Rob

Scattered showers my arse -- Noah, 2348BC.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #14 on: April 16, 2011, 02:16:10 PM »
@Dothos
I have emailed you a hex file to try.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #15 on: April 17, 2011, 10:16:41 AM »
I tried it but a strange thing happened when I connect the A0 to the receiver it stops responding. I turn on the device and connect the rx to tx to make sure it is working alright, then I disconnect them from each other and then connect the A0 to the rx and nothing happens I should be able to see the string appear over and over again. the receiver is powered by the axon so the grounds shared. Is the a possiblility that the adapter gets overwhelmed by the "spam"? Can you make it just send the string once when I press the onboard switch?

Many thanks for the healp anyway

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #16 on: April 17, 2011, 11:40:23 AM »
I'm not quite sure I understand your response...
I tried it but a strange thing happened when I connect the A0 to the receiver it stops responding.
What stops responding to what? The Axon is just shouting the string on pin A0 to try and put the Bluetooth into 9600 baud - all other pins on the Axon are 'unused'. If you mean the Bluetooth has stopped responding - then responding to what?

Quote
I turn on the device and connect the rx to tx to make sure it is working alright,
On what "device"? How are you making sure "it" is working alright - I thought you had nothing that could talk to it - hence me writing the code? You cant be talking about the Axon since I have implemented a Transmit-only-uart, it has no concept of 'receive'

etc.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline rbtying

  • Supreme Robot
  • *****
  • Posts: 452
  • Helpful? 31
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #17 on: April 17, 2011, 11:46:56 AM »
OP, if the string that Webbot's code has you outputting to the Bluetooth changes the baud rate from 1382400 to 9600, then you should probably try connecting to the Bluetooth at 9600 baud to see if it worked - you won't be receiving anything at 1382400 baud if it did.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #18 on: April 17, 2011, 02:41:19 PM »
I'm sorry if I am confusing! I'll try to clarify. The string "AT+ORGL\r\n" is to set it to default I think that is 38400 b/s.

I start of by turning on the bluetooth device and I am using the axon to power it through the 3.3V. I connect the rx and tx (from the device) to each other so when I connect to it from the computer via bluetooth I get feedback just to check if it is working fine.

Then I disconnect them (tx and rx) and connect the rx to the axon's A0 (still connected via bluetooth eith the computer) and I should see in the computer your string being displayed over and over as you said. But, nothing happens and when I reconnect the tx and rx it is not working anymore it seems to have crashed I have to turn the bluetooth device off and then on again for it to work again.

I did all that to make sure the string that is coming out of the axon is recognisable by the device. If so it should be retransmited by the device to the computer but instead it crashes the device.
I hope I am more clear now and I would like to know if you could make it send the string only once when pressing the onboard switch. plz :p

Offline hazzer123

  • Supreme Robot
  • *****
  • Posts: 460
  • Helpful? 3
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #19 on: April 17, 2011, 03:06:10 PM »
You won't see the string being displayed over and over because after receiving it once, the baudrate of the Bluetooth device will have changed, and it will be expecting much lower baud messages. You will get gibberish at the output, if anything.

Have you tried passing it data at 38400 or 9600 baud after trying all this? Maybe it's reset the baud to a sensible rate already?
Imperial College Robotics Society
www.icrobotics.co.uk

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #20 on: April 18, 2011, 06:04:19 AM »
To enter config mode I have to set a certain pin um high. Im just doing this to test the string. And after that I conected the tx to the rx and they are always at the same speed...

Offline hazzer123

  • Supreme Robot
  • *****
  • Posts: 460
  • Helpful? 3
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #21 on: April 18, 2011, 07:22:27 AM »
From the documents on this page (specifically the AT commands doc), it seems that in config mode (with PIO11 high) the BT modules uses the following UART settings:

Quote
baud rate 38400, 8 data bits, 1 stop bit, no parity bit, no flow control

This would make much more sense. The "config mode" should always use a slower, accessible baud rate.

Connect it to your computer, and, with the above settings, send "AT\r\n". You should get the response "OK". If so, send the reset to default AT command.
Imperial College Robotics Society
www.icrobotics.co.uk

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #22 on: April 18, 2011, 08:36:40 AM »
Yes it would make more sense but that ir there just because that is the default rate. In my search I found an online store that sold it too and had a warning about this on the description. It said not to set up the rate above 115k otherwise we couldn't be reset using a computer only using an mcu or sending it back to them lol and I tried it...

Offline rbtying

  • Supreme Robot
  • *****
  • Posts: 452
  • Helpful? 31
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #23 on: April 18, 2011, 10:24:28 AM »
@OP: Have you TRIED to use the 38400baud configuration mode?  Don't trust resellers for everything, especially if the datasheet disagrees with them.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #24 on: April 18, 2011, 11:33:03 AM »
Ok I TRIED again and I must have done something wrong the other 3 times I tried it because now I could connect to it at the 38400 baud I reprogramed it back. lol I am very sorry this was a very noob thing to do and I apologise and thank to all of you who tried and took time to help me do it. And thanks for those who didn't assume I knew what I was doing  :P

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #25 on: April 18, 2011, 05:45:51 PM »
Glad you got it sorted.
For anyone who is interested: this is my attempt to send stuff at 1,382,400 baud on a 16 MHz chip on PORTA0:
Code: [Select]
static void send(unsigned char xmit){

unsigned char stat = SREG;
unsigned char bits;

asm volatile (
"cli" "\n\t"
"ldi %2,10" "\n\t"
"com %0" "\n\t"
"sec" "\n\t"
// Takes 9 cycles to send one bit
"putchar0%=:"
"brcc putchar1%=" "\n\t"
"cbi %1,0" "\n\t"
"rjmp putchar2%=" "\n\t"
"putchar1%=:"
"sbi %1,0" "\n\t"
"nop" "\n\t"

"putchar2%=:"

// Add nops in here where
//    Num nops= ((F_CPU / baud) - 9)
// (16MHz / 1,382,400 baud) - 9 = 3
"nop" "\n\t"
"nop" "\n\t"
"nop" "\n\t"



"lsr %0" "\n\t"
"dec %2" "\n\t"
"brne putchar0%=" "\n\t"

:
: "r" (xmit), "I" (_SFR_IO_ADDR(PORTA)) , "r" (bits)
);
SREG = stat;
}
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #26 on: April 18, 2011, 08:22:50 PM »
Hi Webbot,

Did that really run at 1.3824MHz with all those instructions?

FWIW here's my version, it's real dumb and doesn't send characters yet, this is just a test sending 0xAA.

Code: [Select]
void setup() {
  pinMode (7, OUTPUT);
}

void loop () {
   debug_serout_IO (0xaa);
   
}

#define LO_BIT \
asm("cbi 0x0B,7"); \
asm("nop");  \
asm("nop");  \
asm("nop"); 

#define HI_BIT \
asm("sbi 0x0B,7"); \
asm("nop");  \
asm("nop");  \
asm("nop"); 

void debug_serout_IO (unsigned int val) {

        HI_BIT;

        LO_BIT;  //start
        HI_BIT;  // B1
        LO_BIT; // B2
        HI_BIT; // B3
        LO_BIT; // B4
        HI_BIT; // B5
        LO_BIT; // B6
        HI_BIT; // B7
        LO_BIT; // B8
        HI_BIT; // stop


delay (5); // stop bit
}

BTW, my dyslexia is showing again, in my previous posts I was working on 1.83824MHz when it should have been 1.3824MHz. This version runs at 1.333MHz which is close but still no cigar.

Anyway I guess it's moot now, but an interesting exercise.

______
Rob

Scattered showers my arse -- Noah, 2348BC.

Offline DothosTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #27 on: April 19, 2011, 11:26:00 AM »
I did further testing and realised I was right after all I now set the speed to 230400 and I can only access the config mode at that speed. So I assume the program Webbot sent me for the axon worked and reconfiged the bluetooth module back...

Offline hopslink

  • Robot Overlord
  • ****
  • Posts: 202
  • Helpful? 14
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #28 on: April 19, 2011, 01:57:18 PM »
Quote
Did that really run at 1.3824MHz with all those instructions?
Webbot's send loop is 11 instruction cycles per bit, giving a baud rate of 16000000/11 = 1.4545MBaud on a standard Axon/ATMega.

@Rob - Yours seems to be 4 instruction cycles per bit which should be 4MBaud @16MHz by my calculations... If it is sending at 1.33MBaud then I would suspect that there may be some additional state saving/restoring being added by the compiler for every line (SREG?). That throws up interesting questions about the merits of single inline assembly instructions.

Interesting to see the different methods of implementation too. 

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Bluetooth to uart super fast in axon 2 need help!!
« Reply #29 on: April 19, 2011, 02:13:22 PM »
Webbot's send loop is 11 instruction cycles per bit, giving a baud rate of 16000000/11 = 1.4545MBaud on a standard Axon/ATMega.

Mine was based on an Atmel document - which claims 9 cycles per bit. I then added 3 nops to bring it up to 12 - so should be 16000000/12=1,333,333 baud

Webbot
PS Happy to proven wrong
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here

data_list