BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 8:28 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: serial communication
PostPosted: Wed Sep 08, 2010 9:37 pm 
Offline
Citizen

Joined: Thu Aug 19, 2010 9:34 pm
Posts: 17
I'm trying to find some code on this website to show me how to setup and communicate using the two serial ports on ATOM Pro 24m.

Programming is totally foreign language to me. I can't make sense of the syntax manual. I really need to see working example - the whole thing from declaring variables and constants all the way to the "end" statement.

I need to read ASCII string, save it in RAM and send it out to see it work in Windows HyperTerminal. Let say read it on one serial port, send it out on the other and vice versa. Then I can tell that the micro is doing what it is supossed to do.

Most likely I have my string array setup incorrectly, or I'm missing some other small thing.

Is there any program I can read or download to see what I'm doing wrong?


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Wed Sep 08, 2010 10:49 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
Hello, beginner. When you say, "the two serial ports" that immediately rings alarm bells. The BAP40 has two hardware UARTs, the BAP24 and -28 have only one. As for software serial, you can have as many ports as you have available I/O pins, but these can be used only one at a time.

We need some basic info, like:
- which version of Studio you have.
- the operating system on your computer.
- what kind of circuits you have your modules installed in, that is, are you using a commercial development board or a breadboard or what?
- give us a simple drawing (or better yet, a schematic) of your circuit.
- confirm you are using the hardware UARTs for serial communications, or are you using software (bit banged) serial ports?
- your entire code as you have written it so far.
- a detailed description of what you are trying to do.

That's the initial input.
Take care.
kenjj

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Wed Sep 08, 2010 11:16 pm 
Offline
Citizen

Joined: Thu Aug 19, 2010 9:34 pm
Posts: 17
Huh, lot of info I have to get together.

Basic Micro Studio 1.0.0.35
Windows XP Pro

The ATOM Pro 24m is on perfboard with wires hanging all over since I don't have better setup at this point.

The programming serial port has DB-9F wired as shown in the ATOM Pro 24m datasheet and does work with Studio. The second serial port on pins 14 and 15 is hooked up to RS232 TTL converter. It is of-the-shelf converter using MAX232.

For sake of the code example, imagine 2 computers running Windows HyperTerminal with the BasicMicro between them. The BasicMicro has to read one serial port, save the ascii string in RAM, and send it out on the other serial port. That's all I want to see right now. Once I get this far, I can play with the string to modify the ascii data to the format I need, but so far I wasn't able to figure out how to read a port, write to port, or even verify that my settings - including the string array are done correctly.

I'm not trying to learn programming. I'm looking for working code example. Are there any on BasicMicro website?

Thanks for your help.


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Thu Sep 09, 2010 3:10 am 
Offline
Citizen

Joined: Thu Aug 19, 2010 9:34 pm
Posts: 17
Additional info.

I just noticed something weird. When nothing is connected to my PC serial port, Windows HyperTerminal doesn't echo anything I type.

When I connect the Atom Pro 24m programming serial port, everything I type is echoed back to HyperTerminal without any program running on the Atom Pro 24m.

When I connect the Atom Pro 24m "hardware serial port" and run simple "hserin / hserout" program that falls through after short delay and ends (no loop), I get one character echoed to HyperTerminal.

What confuses me here is why does the programming port echoes when I don't have the Atom programmed to do that. Can the programming port be used for my application, or do I have to add another DB9 connector and RS232 to TTL converter? These things aren't explained anywhere and I hate to reinvent the wheel. It would be an ugly wheel without tire ;-)


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Thu Sep 09, 2010 9:49 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
The AtomPro 24 and 28 modules have a hardware loop back echo on anything you send it. That is because the s_in and s_out pins are half duplex pins sharing a single I/O. The AtomPro40 uses 2 seperate I/Os because one of it's 2 hardware serial ports is on the s_in and s_out pins.

As for whether this port can be used to talk to your device I need to know what device you are talking to. A link to a datasheet would also be nice. If all you are doing is reading from some other device than I'd say there should be no problem at all. If you have to send data back to the device then it depends on if the device will get confused by the echoed data. Anything it sends to the modules s_in port will be echoed on the s_out pin. If this will confuse it then yes, you will need to put a db-9 on other pins(I suggest p14 and p15 since they are the hardware serial port pins). If the device you are talking to can talk with TTL levels then all you need is the db-9. If however the device is talking with RS-232 levels(ussually +-12v) you will need a max232 or equivilent circuit as well.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Thu Sep 09, 2010 4:36 pm 
Offline
Master
User avatar

Joined: Tue Jul 07, 2009 9:06 am
Posts: 120
Location: Wisconsin USA
Try this.

Code:

enablehserial

SETHSERIAL H9600, H8databits, Hnoparity, h1stopbits
pause 50


main
test var sword

hserin 800000, main,[dec test]
hserout [dec test]

goto main



hserial uses p14 and p15 not the s_in/s_out.

RX is p14 so the max232' TTL-TX goes to p14, and the max-RX to p15

Send a decimal number to the BAP from a terminal program, i strongly prefer This One
And it should send it right back, giving everything is connected right.

Now then, i personally use 2 serial ports on my computer at the same time, a hardware serial port for programming, and a USB serial adapter for the terminal for hserin based commands.
Hope this helps.

serial commands take a bit of getting used to, i had trouble with them at first too.

_________________
Image
Basic Micro Blog
Universal Robot Controller


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Thu Sep 09, 2010 5:13 pm 
Offline
Citizen

Joined: Thu Aug 19, 2010 9:34 pm
Posts: 17
Thank you.

What I learned so far is that the programming port is not a good choice for most applications. I had to install second RS232 to TTL converter and use P13 and P12 for the software UART. I also learned the hard way how to program the micro to send and receive on these two ports (hardware port and soft-uart) since I didn't find any working code samples.

Now I can receive ascii strings on "hserin", send it out on "serout" and vice versa. It was hard to put it all together. I'm not a programmer. I had to "figure out" how strings are setup, how they are accessed, etc. To me it was waste of time because when I won't do any programming, I will forget it all. I just needed sample code to copy. There is none! People make money writing books on programming and this entire website doesn't have one working code sample. Hey, somebody should pocket on that. Is anybody out there?

Thanks again for your help (and the link).


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Thu Sep 09, 2010 6:55 pm 
Offline
Master

Joined: Sun Oct 05, 2008 9:40 am
Posts: 111
I use the Sin Sout port just fine in most my projects.

The statment that there is no example code is false. There might not be anything you can cut and paste but there is plenty of example code (Some posted by myself).

Serin S_in , I9600, [STR string\3]

Serout p15, I9600, [STR string\3] 'Not using Hser


'STR is string modifier
'\3 sets # of bytes in string

More info will lead to a less general answer.


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Thu Sep 09, 2010 7:14 pm 
Offline
Citizen

Joined: Thu Aug 19, 2010 9:34 pm
Posts: 17
Thanks for your help. You may be right that there are some (maybe many) "one-liners", but that is useless to a beginner like I'm. When you don't setup your variables and omit the "enablehserial" like the manual I received did, your program won't even compile - never mind work. I needed one working example how to do the "housekeeping" and write a program that works. Yeah, if it was my hobby, I would play, but I'm under pressure to get this project done or lose my job. You bet I'm nervous. Only thanks to this forum and Nathan's input I was able to get where I'm now. I still have lot of code to type, but it will be only byte conversion and bit manipulation not anything specific to the micro's hardware or firmware.
Thanks guys for your help.


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Fri Sep 10, 2010 1:06 am 
Offline
Citizen

Joined: Thu Aug 19, 2010 9:34 pm
Posts: 17
This question is more or less for the ATOM Pro 24m designer.

Is the software serial port buffered? Usually even bit-banged serial has at least small 8-byte wraparound buffer.

I need to figure out some timeout values to jump from one serial to another trying to read both without losing any bits.

My math is very weak, but I think, at 9600bps 8N1 there should be 960 bytes per second. That's little over a milisecond per byte. A two milisecond timeout should be sufficient to assume there is no byte available.

Is my theory correct?
Any suggestions?


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Mon Oct 04, 2010 2:32 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Software serial is never buffered on any processor. If it's buffered it's hardware based somehow (uarts,timer interrupts, something). Software serial (serin/serout) runs in the foreground (as your code executes). If you are not in the serin command you will not receive any serial data and any data sent to the pin will be lost.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Tue Aug 23, 2011 2:15 pm 
Offline
New User

Joined: Tue Aug 23, 2011 2:00 pm
Posts: 2
Hello there. I have a very similar question to that of beginner.

I want to be able to send/receive data to/from my Basic Atom Pro 28 (mounted on a Lynxmotion Bot-Board II) using the serial port (USB to dub-9) of my computer. I have no problems loading programs to the chip using my USB-to-DUB9 cable through the built-in dub-9 of the bot-board II but I can't seem to send/receive anything on the serial port. In addition, I'm a bit confused with the s_in/s_out and hserin/hserout commands.

I am also looking for example code in these forums, however and as beginner noted, it is scarce. Although beginner mentioned he solved his issue it is unfortunate he didn't share code and other valuable information.

Thanks in advance for your help!


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Tue Aug 23, 2011 8:43 pm 
Offline
Citizen

Joined: Thu Aug 19, 2010 9:34 pm
Posts: 17
When you visit this board, you're talking to the people who invented the BasicMicro, people who wrote the firmware and the downloader software. Year passed by and they still didn't write human understandable manual, or provided short sample code. Hey, you're on your own!

I would like to help you, but I'm not a programmer. Programming is not even my hobby. I had to repair obsolete piece of hardware for which parts are no longer available and the BasicMicro controller was just the right part to make it possible at reasonable cost. In my opinion it is great little controller, only the tech support is lousy to say the least.

I don't remember all the details. I can provide you only with some notes I wrote when I was fighting the serial ports.

First, if you want to use the programming serial port, you have to disable the bootloader. You need to disconnect the ATN pin from the DB-9 connector DTR pin probably by cutting PCB trace on your programming board. I used pin header and shorting block to make it easy.

The programming port doesn't make good serial port for an application. It is missing characters unless you dedicate the full processing power to loop in the serial routine, but can be used for output port if your receiving end is buffering data. I used it for display on laptop and it also worked with 20 character LCD.

The hardware serial port is buffered and works good. It is TTL port and may require TTL to RS-232 converter. You just have to enable it at the beginning of your program:
enablehserial
sethserial h9600,h8databits,hnoparity,h1stopbits

Your main program loop can now read the serial input:
scan_loop
scanstring = 0\32 ;set string to all zeros
hserin 5000,timeout_h,[str scanstring\16] ;read string up to \n long
timeout_h ;fall through if no data for 'n' miliseconds
if scanstring(0) = 0 then scan_loop

Now you can send the received serial data out on the programming port and verify it on a PC:
test_1
serout s_out,I9600,[str scanstring\16,13,10] ;send ascii string \n long, followed by CR LF.

------------------

There. Modify it any way that fits your application and maybe post some working example for the next sucker like the two of us who bought the controller and couldn't get clear explanation.


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Wed Aug 24, 2011 7:29 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
Hi Beginner and ferre and others,

There are others of us who did not write the firmware or the like but that use the boards and try to answer questions... The manual is in much better shape than it used to be. Yes it could be better.

the forum up at http://www.lynxmotion.net is much more active and is where the majority of the users who use the Basic Atom Pros communicate.

On the BasicAtomPro28, the S_IN/S_OUT pins are connected to the DB9 connector, where you can use serin/serout on them. There are some complications with this as they actually only use one IO pin, so there are issues about echoing of characters and the like... The serin/serout functions are bitbang and you can only receive data when you are actually sitting in a SERIN call when the data arrives.

HSERIN/HSEROUT - are not connected to the DB9 connector but are instead connected to IO pins P14 and P15 on the BAP28, which are TTL level signals. Work great with things like XBEES and the like. The data is buffered and the software maintains a queue of characters that was received.

There is lots of code available up on the Lynxmotion site, not sure what to direct you to as I am not sure what you are looking for.

Good Luck
Kurt

P.S. - Nathan (Acidtech) - On Arduinos there is actually input buffering on SoftwareSerial, especially with NewSoftSerial (I prefer the beta version of this). Yes it does use some hardware support for this (Pin Change Interrupt). But it works well enough that I can write a real simple SSC-32 foreworder function that works great on the Megas with multiple USARTS, but also works well on the UNO with only one USART.
Code:
void SSCForwarder(void)
{
    int sChar;
    int sPrevChar;
    Serial.println("SSC Forwarder mode - Enter $<cr> to exit");
   
    for (;;) {
        if ((sChar = Serial.read()) != -1) {
            SSCSerial.print(sChar & 0xff, BYTE);
            if (((sChar == '\n') || (sChar == '\r')) && (sPrevChar == '$'))
                break;    // exit out of the loop
            sPrevChar = sChar;
        }
       

        if ((sChar = SSCSerial.read()) != -1) {
            Serial.print(sChar & 0xff, BYTE);
        }
    }
    Serial.println("Exited SSC Forwarder mode");
}

I have tried but never had much luck doing something similar on the BAP... But again this is off topic :oops:

Kurt


Top
 Profile  
 
 Post subject: Re: serial communication
PostPosted: Wed Aug 24, 2011 2:09 pm 
Offline
New User

Joined: Tue Aug 23, 2011 2:00 pm
Posts: 2
Hi Kurt, Beginner and Acidtech.

Thanks a lot for your help!! Now I understand what was the issue with the programming port and the hardware serial port. Will work on a XBEE or with a max232.

I'll keep you guys posted!

Andres


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO