![]() |
Forum Index : Microcontroller and PC projects : Micromite 170 comm port issues
Author | Message | ||||
OA47 Guru ![]() Joined: 11/04/2012 Location: AustraliaPosts: 986 |
I have an issue with a program using MMBasic 5.4.4 on a MX170 28 pin chip. I am using Com1 Rx at 9600 and opening and closing the port in a sub that does not call any other subs but has interrupts that don't involve the port. As the Tx pin for Com1 was not being used I thought I would be smart and use it to produce a log file. During the Log File sub I am using Com1 Tx at 38400 and again opening and closing at the end of the sub. The problem I am having is occasionally the program stops on error Com port already open. I thought I had found the problem by putting a 200 mS pause after Close #1 which seemed to fix the problem but alas it still happens but not as often. Any suggestions welcome OA47 |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
Flags. Flags are good. ![]() Set a flag when you open the COM port, and clear it when you close the COM port. Check the flag to find out if the COM port is still open BEFORE you try to open it again. If the flag is set, then close the COM port, THEN re-open it. Personally, I like to reserve the COM ports, so if I am using them in a program, I open them at the top of the code, and leave them open. They are dedicated to the serial device they are connected to and are not used for anything else. That works for me, and is just my method, but I can see why you want to close and re-open, so you can nab those pins for other uses elsewhere in your code. Smoke makes things work. When the smoke gets out, it stops! |
||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
+1 I usually leave the port open. I do, however have a situation where I connect to a device that defaults to 19.2K BAUD but I need to run much faster. I open at 19.2, issue a command to the other device to switch to 115K, close my port and re-open at 115K. This must be the first time I have ever closed a port. Craig |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
As Tinine suggested... just leave it open I do the same with SPI ports. Opening and closing might sound like good practice but it's only your stuff running and just save yourself the time. Most of my code has an open in the preamble and no corresponding close. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
He can't leave the port open. He is using it at two different baudrates. Flags and do all the work in the one main loop to prevent an interrupt getting in the way. Jim VK7JH MMedit |
||||
OA47 Guru ![]() Joined: 11/04/2012 Location: AustraliaPosts: 986 |
I have to close the port and re-open to change the baud rate for each routine. If I don't the log file would have to be generated with the slow speed that the Rx is running at and this would introduce more Rx downtime while the log is being written. ![]() OA47 |
||||
bigmik![]() Guru ![]() Joined: 20/06/2011 Location: AustraliaPosts: 2950 |
Hi OA47, Could you not use another comm port to write your log file? Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
OA47 Guru ![]() Joined: 11/04/2012 Location: AustraliaPosts: 986 |
Mick, all other ports/pins are in use. Although Com1 Rx is monitored by the program I thought I would use the Com1 Tx as it was a spare pin and not used. I have inserted a ComOpen flag and check this before trying to OPEN the port. It took around 24 hours for the last error to appear (Port opened and closed probably 1000 times) Will see what happens from here. OA47 |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
There is also the Cfunction/Csub serial transmitter for any pin if you want to use that. Probably not possible, as it sounds like you have used all the other pins for things. It is amazing how easy it is to use up all the pins on the 28-pin device. ![]() I guess that is where the 44-pin chip could help you, but probably a bit late to suggest that, yes? Smoke makes things work. When the smoke gets out, it stops! |
||||
Chopperp![]() Guru ![]() Joined: 03/01/2018 Location: AustraliaPosts: 1097 |
Hi OA47 For what it is worth, I use ON ERROR SKIP immediately before OPEN or CLOSE COM commands when sorting out comms issues similar to yours. This may help. Brian ChopperP |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
ah. yes... didn't read the post properly, soz ![]() |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |