![]() |
Forum Index : Microcontroller and PC projects : VAR SAVE Problem
Author | Message | ||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1642 |
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: AustraliaPosts: 6283 |
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: AustraliaPosts: 1642 |
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: AustraliaPosts: 3292 |
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: AustraliaPosts: 1642 |
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: 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: AustraliaPosts: 3292 |
Thanks Bill, you have spotted a bug in the manual ! I will fix it in the next release. Geoff Graham - http://geoffg.net |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |