UART recieving using Basic Atom 28 pin plus BOT BOARD II

Hello,

I have a problem receiving bytes of data from my bluetooth device. the device is currently working on an UART interface with 9600 baud rate 1 stop bit and no parity. I attempted to access the data by plugging the output of the bluetooth to the c7 (PS2) pin of the Basic Atom Bot Board II. For this I used the ENABLEHSERIAL, SETHSERIAL, and HSERIN. The Program however got stuck with “sethserial h9600”.

I guess I want to know how we could receive this data form a 1 wire device? Am I doing it correctly?? And if so how would i get the sethserial command to work properly?

Thanks
Krish

By stuck do you mean you were running in debug mode? Also posting your actual code would help. Also if the bluetooth devices serial side and work with a PC then you will need a MAX232 or equiv to connect it to the Atom. I’m not sure if you mean by “uart” that that is how you have it connected or not so clarification would help. Also model number and or datasheet link to the bluetooth device would be helpfull.

Well by stuck I mean the program does not progress through the code after hitting the sethserial command. I do not have a copy of the code, but basically we are controlling the Lynx 6 Robotic arm via the Basic Atom, and therefore just telling it to move to different positions. In our code, we basically have the robot arm moving from position 1500 to 1400 back to 1500 for all motors in a continuous fashion. However, in between I am attempting to read in a byte from an external device. This is where I have placed the sethserial command as well as hserin command. The Arm however only performs the first bit of actions, and then ceases to work after. If I comment out this part of the code, then the arm continues in the loop indefinitely. So I am unsure to what the problem is exactly :confused:

The UART is a form of communication between microcontrollers, PC, etc. It basically converts data into bytes which is a standard form of communication. Right now a 68HC11 with MAX232 is sending the data using the UART format to send its data across the bluetooth device, and I am trying to receive the byte from an output pin on the bluetooth device. Sorry, the model number for the bluetooth device is eb-501 SER. The link for the data sheet is here ( a7eng.com/products/embeddedb … 01-SER.htm ).

So are you saying that the Basic Atom does not have the MAX232??? The PIC16F86/7 processor says it is able top decode USART data. I am unsure as to how to do this with the Basic Atom though. I am looking at the pdf file for the PIC16F87 (robotstore.com/download/247097.pdf) page 104. Since the Basic Atom uses this device, I thought it would be able to decode the data without a problem. If you have any ideas I would appreciate it.

Thank You

So in other words you don’t know if you program is stopping at SetHserial or if it is stopping at HSerin.

A MAX232 is NOT a usart. It is just an inverter. You still need an inverter to talk to another device using an inverter(eg a PC). The S_IN/S_OUT pins on the atom have an inverted on them already but those pins do not connect to the hardware usart. Only P6 and P7 connect to the usart. You must add an inverter to use these pins to talk to a PC.

If you are connecting the P6/7 pins directly to a PC serial port you have probably already fried parts of the Atom module. You must use an inverter(which can take the ±12v coming from the PC serial port and convert it to an inverted 0-5v signal) to talk to a PC serial port. That could explain why your program is freezing at the HSerin command. It’s not getting any data because the pins are dead so it is waiting forever for data that it will never get.

Also the BasicAtom is based on the 16F876/7 not the 16F86/7. I assume thats a typo on your part but want to be sure.

I am starting off the interface by connecting a 68HC11 to the bluetooth device, and NOT a PC. I have no intention of using a PC. All I need is the ability to obtain bytes of data from this microcontroller (which also uses 5V signals which is then transmitted through bluetooth again using 5V signals).

I also know its only the sethserial part because I tried just commenting it out and running it with hserin, but the hserin command does not do anything anyway while the robot arm moves continuously. Also the Basic Atom is not fried since it still performs its regualr function.

Basically I need to know how to obtain a byte of data using the USART? I am unsure how this is done using the Basic Atom. So if I connect an inverter and then placed the data through P6/7 pins, how would I go about obtaining it. Sorry If I am bothering you but I am trying to understand on how to work with the Basic Atom.

Thank You

Can you connect your bluetooth device to a PC and see what the 68HC11 is sending out to confirm the bit rate and that the data is valid?

To receive a byte of data using the hardware serial port on the Atom you must SetHSerial at the correct bit rate and then you must use hserin with a variable to store the incoming data. If no valid data is recevied hserin will block indefinitely unless you use a timeout.

Please post your test code.

I read through the quick start for that bluetooth serial adapter. It’s rather confusing. It sounds as if you have to setup it’s baudrate ahead of time using a PC.

Sorry for the late reply, I just had a few exams and things to deal with last week.

As for testing the bluetooth device, I had connected it to another similar HC11 device to display the incoming byte on its LCD screen. Both LCDs showed the exact same data which would mean that the byte checks out. I was unsure as to which programming software I would use to view the byte through a PC and so I thought I would use another HC11 device to test it.

Here is a text file of the program that I have been attempting to work on. I have commented out places that I tried to place various commands to read in the Byte of information. I am going to continue to troubleshoot for my UART problem.

Here I am making ant 0 and 255 with a 5 second delay in between to allow the Lynx 6 time to perform its action.

As for the bluetooth device, we were unsure as to how we could setup the baudrate through hardware, and therefore we are using the factory standard of 9600.

I also saw in the BASIC Micro User’s Guide that comes with the Basic Micro IDE that the hserin is hardwired to P15. It says this in page 197 of the user guide (Revision 2.2) under the explanation section. If thats the case, then is it necessary to have the SSC32 wires connected to pin 15 or can I switch them to another pin?

Thank You.

Just move the wire and change the pin number. :wink:

HAHA, yea thats probably the easiest thing I have fixed so far on my project :slight_smile:. So it is necessary for me to use a max 232 regardless whether i am using serin or hserin??? thats what I am planning on trying next.

Ug… You do not need to use a level shifter to connect the SSC-32 to a Bot Board. :unamused:

This tutorial shows how it’s done.
lynxmotion.com/images/html/build091.htm

I’ll make up a nifty drawing to illustrate this better. Gimme a few.

Yea thats what I figured, because when I gave my max 232 the bluetooth signal, the voltage at the output of the 232 was 14V. I Figured me connecting that to the Atom will definitely make some sparks fly.

I am going to connect the output of the bluetooth to the Basic ATOM board (one of the input pins) and not the SSC-32. The SSC-32 and Atom Board are already connected using the serial data connection. So basically I connect my bluetooth interface to where the PS2 data is going to (P4)? Do I still use serin on the Basic Atom to read the data in? I want to read the byte and use the value.

I am still having issues using hserin or serin to read in UART data from the bluetooth. I am unsure as to where the problem is. If anyone has worked with the Basic Atom UART before for the 28 pin micro controller, can you please help me. I have tried everything I can think of to attempt to get the UART interface to work with no luck.

First, if you can’t get it to work with serin don’t try getting it to work with hserin. Focus on getting it to work with serin first. Once you have that then move on to hserin. Write a simple program on the Atom to read in a value from the input pin you specify and then to send that byte back out another pin you specify and hock those pins to the bluetooth device. Then on the other side of the bluetooth device have it send and receive the data. until you can do this simple process moving on to anything more complex is pointless. Also one serin is working you can post the baudmode you had to use and I can help you from there.

I believe I have found my problem. It works when I continuously send data from the bluetooth without a delay in between bytes. So Serin and Hserin both need to be able to read the byte right off the bat before it can store it into the variable. I guess at the time serin or hserin is used, if the data is not there then it will stop the program there. I sent my byte faster this time with a 0.005 ms delay between each byte and the Basic Atom does read in the byte. But while using the debug program, i noticed that the byte value was continuously changing. I am sending a value of 100 through the bluetooth and receiving 97, 207,145 etc. I am guessing is that after serin is called, it reads in any 8 bits it finds, even if its not the complete byte I am sending. So when I ask to read in the value and offset the robotic arm’s wrist to that position, it varies by the numbers it thinks it is reading in from the bluetooth. My next step is I will try to read in the data using the interrupts so that it receives the proper byte.

P.S. sorry for late reply, had Exams.

Also remember the SSC-32 V2.01XE has the ability to change the delays used when processing (responding to) a Q command.

Here is the code I made with the interrupts. The program just goes ahead and enables the interrupt, but never ever jumps to the interrupt handler. then Atom book tells me to use “oninterrupt RCINT” but yet it doesnt recognize the interrupt, unless again it is not reading the right data. What I need to know is which pin does the RCINT recieve the byte of data from to set off the interrupt?? is it the DT pin?

A) you haven’t setup the hardware serial port(usart) registers to turn on the receiving unit. You haven’t setup the bit rate. There are a lot of things you will have to do to use the RCINT at all.

B) you can’t use software serial commands(eg serin) on the usart pins when the usart is turned on.

I suggest you get the PIC16f876 datasheet and read through the section on the USART before you try jumping into this. A simpler interrupt to start playing with is the timer1 overflow interrupt. Again you need to read the section on timer1 in the PIC16F876 datasheet.

The ONINTERRUPT command simply tells MBasic were to jump when an interrupt happens. The ENABLE command simply enables the interrupt so if one is triggered MBasic will jump to the specified label. Neither sets up ANY other registers that may be needed to actually generate the interrupts.

The code you have isn’t even close to what your final program will have to look like to function properly. I’m talking about a LOT of work left.

Quick explanation of the code. I read in the RCREG and store it into temp. RCREG is where the data is received from and gets stored. Then I check if that data is the same as the one I previously received. If it is then I just jump back to the loop. If it is not then I display temp on the debug window to see the new value. In the interrupt handler, I placed a dummy debug so that I will know when or if the program did jump to the interrupt handler.

This is the code I have tried based off the data sheets they have online. The good thing is that I am successfully able to access the receive register and get the byte for data processing. Bad thing is I am still unable to get the program to the interrupt handler.

I was observing the code through the debug code (BEST TOOL IN THE IDE!!!), and it gives me the proper values when I read in the RCREG through temp. This would mean that I did not either enable the interrupt properly or that the “enable rcint” and “oninterrupt rcint” are not doing the job I want it to do. Also in the PIC data sheet it said something about clearing the RCREG register, which I tried looking for a command to clear the register but cannot find one. Maybe that could be a reason why the interrupt is not working because the RCREG register is never cleared. I also tried using the commands that the PIC specified to set the interrupt with no luck.

I am going to continue to play around with this to try figure out where my problem is, please give me any advice.

leopard.t.u-tokyo.ac.jp/lect … 16F87X.pdf (page 103) in case you need the reference.

Also I have tried the commands CLRC, CLRF and CLRW to clear the RCREG with no success.

Basically how this code works is that it uses external interrupt instead of using the RCINT (which I have basically have given up since this does the task efficiently :smiley: ). So it detects either the first zero bit or the stop bit (if the data sent is all binary 1s) and then executes the interrupt. In the interrupt we disable it first so that it will not detect the next transition from high to low. First I wait for about 0.1 ms so that the complete byte is received in the RCREG register and then I store the byte into a variable. It exits the interrupt handler to the original code it was in. In the code, it first checks if the byte it just received is the same as the one previously received. If not then it displays it on the debug menu and stores or updates it so that next time we check we will not need to display it again. Basically, it will only display when a new byte is received.

For this code to work however, the UART input MUST be set to 9600 baud and also NEEDS to be connected to pin 15. The bytes I send are equivalent to the decimal value of 99, 100 and 101, which is continuously sent. This is also seen on the debug window. If however someone knows how to do this using the receive interrupt, I will gladly accept your input on the matter.