Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:53 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : VAR SAVE Problem

Author Message
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 03:51am 04 Nov 2018
Copy link to clipboard 
Print this post

Hi All,

I'M having trouble with the VAR SAVE command. It appears to be corrupting messages sent to Com2 to which I have Terra Term connected. The program below will save the variables if rto% is not 1 but but will save them if it is anything else. The escape sequences in SUB CLS2 are still being transmitted in the background while the VAR SAVE command is happening. If I un-comment the line 12:

' DO: LOOP UNTIL LOF(#2) = 256: PAUSE 20 ' Wait til message sent

OR

If I comment out the line with the VAR SAVE command in it the text is displayed correctly on Terra Term. MMBasic is version 5.0405 and I'm reluctant to try a later version because the chip is on a breadboard under a birds nest of wires and difficult to remove. I see nothing in the change log that mentions this problem.

Am I missing something or is this a bug?

Thanks
Bill

OPTION EXPLICIT

DIM MyAdd%=1, bd% = 2, DOPulse% = 10
DIM MyAdd2% = MyAdd%, bd2% = bd%, DOPulse2% = DOPulse% ' Temp values
DIM rto% ' Response Time Out
DIM STRING baud(3) LENGTH 5 = ("1200", "4800", "9600", "19200")
PRINT " MMBasic version "MM.VER
DO
INPUT "Enter rto value "; rto%
OPEN "com2: 9600" AS #2
CLS2
' DO: LOOP UNTIL LOF(#2) = 256: PAUSE 20 ' Wait til message sent
IF rto% = 1 THEN
PRINT #2, " TIMEOUT! Settings not changed."
ELSE
MyAdd% = MyAdd2%: bd% = bd2%: DOPulse% = DOPulse2% ' update the variables
VAR SAVE MyAdd%, bd%, DOPulse%
END IF
PRINT #2, " Now Running Modbus Slave..."
DO: LOOP UNTIL LOF(#2) = 256 ' Wait til message sent
PAUSE 20 ' and a bit more to be sure
CLOSE #2
LOOP

' Escape codes to clear the VT100 screen
SUB CLS2
PRINT #2, CHR$(27) "[2J" CHR$(27) "[H"
END SUB

Keep safe. Live long and prosper.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 05:11am 04 Nov 2018
Copy link to clipboard 
Print this post

COM2 is done in firmware rather than a UART.
I expect that the VAR SAVE is interfering with the timing of COM2.

Jim

VK7JH
MMedit
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 05:28am 04 Nov 2018
Copy link to clipboard 
Print this post

Thanks Jim, That makes sense. I'll leave line 12 in the program.

Cheers,
Bill
Keep safe. Live long and prosper.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 03:09am 05 Nov 2018
Copy link to clipboard 
Print this post

Good deduction Jim.

Yes, writing to the flash is one of the few times where PIC32 interrupts must be temporarily disabled and that would disrupt send/receive on COM2 which depends on a regular timer interrupt.

Something to add to the manual.
Geoff Graham - http://geoffg.net
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 05:47am 05 Nov 2018
Copy link to clipboard 
Print this post

Thanks Geoff,

I use:

DO: LOOP UNTIL LOF(#fnbr) = 256: PAUSE 20 ' Wait til message sent

elsewhere to be sure that the message has been sent before closing the Com port. The extra pause seems to be necessary because it seems that although the buffer is empty the last byte is still being sent. Closing too early results in an incomplete message transmitted.

On that subject, the Micromite manual says under the heading Reading and Writing:

  Quote  When outputting to a serial port (ie, using PRINT #n, dat) the data will be held in a memory buffer while the serial port is sending it. This means that MMBasic will continue running the program while the data is being transmitted. If you want to be sure that all the data has been sent (perhaps because you want to close the port) you should wait until the LOC() function returns zero indicating that there is nothing waiting to be sent.


Should that be: 'wait until the LOF() function returns 256 indicating...'

I plan to use the same method to implement a DE pin for RS485 without using an inverter ie:

Raise the 'DE' pin
transmit the message
wait til transmission complete (as above)
lower the DE pin

Bill
Keep safe. Live long and prosper.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 12:36pm 05 Nov 2018
Copy link to clipboard 
Print this post

Thanks Bill, you have spotted a bug in the manual !
I will fix it in the next release.
Geoff Graham - http://geoffg.net
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025