Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 13:25 11 Nov 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 : Checking options at runtime

Author Message
TrevorH
Senior Member

Joined: 06/04/2018
Location: United Kingdom
Posts: 145
Posted: 01:16pm 08 Jun 2018
Copy link to clipboard 
Print this post

Hi everyone!
Is there anyway to check that an option has been set VERY early in a program before running the meat of the program and if not set giving an early exit without crashing the pic32?


Trevor
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1671
Posted: 03:10pm 08 Jun 2018
Copy link to clipboard 
Print this post

Yes, I guess a CFunction would easily do that.
From CFunctions.h

//The Option structure
struct option_s {
char Autorun;
char Tab;
char Invert;
char Listcase;
char Height;
char Width;
int PIN;
int Baudrate;
int ColourCode;

// display related
char DISPLAY_TYPE;
char DISPLAY_ORIENTATION;

// touch related
char TOUCH_CS;
char TOUCH_IRQ;
char TOUCH_SWAPXY;
int TOUCH_XZERO;
int TOUCH_YZERO;
float TOUCH_XSCALE;
float TOUCH_YSCALE;

// for the SPI LCDs
char LCD_CD;
char LCD_CS;
char LCD_Reset;

// Note the next options are only applicable to the MM+

char SerialCon;
char SDCARD_CS;
char SD_CD;
char SD_WP;
char DISPLAY_BL;
char DISPLAY_CONSOLE;
char DefaultFont;
char KeyboardConfig;
char TOUCH_Click;


// To enable older CFunctions to run any new options *MUST* be added at the end of the list

But I can't do that at this time.

Regards
Michael
causality ≠ correlation ≠ coincidence
 
TrevorH
Senior Member

Joined: 06/04/2018
Location: United Kingdom
Posts: 145
Posted: 03:56pm 08 Jun 2018
Copy link to clipboard 
Print this post

Thankyou for your reply, but I don't understand what you are telling me.

The problem I have is:-
my program uses the RTC on an E100 board, if I run the program without setting the RTC options, it crashes the PIC32. This forces me to do the multiple !!!!! thing to recover.
I would like to trap the fact that the RTC options are Not set BEFORE I run any more code.

Trevor.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1671
Posted: 04:30pm 08 Jun 2018
Copy link to clipboard 
Print this post

  TrevorH said  
my program uses the RTC on an E100 board, ...

Upps, I guess there are no Cfunctions for the E100 (MMX?) possible.
Maybe Geoff or Peter have an idea? I am Sorry!
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10570
Posted: 04:33pm 08 Jun 2018
Copy link to clipboard 
Print this post

E100 is MM+ so no issue with cfunctions
 
PicFan
Senior Member

Joined: 18/03/2014
Location: Austria
Posts: 133
Posted: 04:47pm 08 Jun 2018
Copy link to clipboard 
Print this post

Maybe is this a solution ?


ON ERROR SKIP
RTC GETTIME
IF (MM.ERRNO <> 0) THEN
PRINT "NO RTC OPTION"
END
ENDIF
Edited by PicFan 2018-06-10
 
TrevorH
Senior Member

Joined: 06/04/2018
Location: United Kingdom
Posts: 145
Posted: 05:36pm 08 Jun 2018
Copy link to clipboard 
Print this post

I think by running a RTC command is what is crashing the PIC when RTC options NOT set, but will check this out.
I was wondering if there is a way of checking which options are set or not Before running device dependant code.

@twofingers I am running a CFunction to enable a CPLD TFT screen already

Trevor.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1671
Posted: 05:50pm 08 Jun 2018
Copy link to clipboard 
Print this post

Trevor,

I fear there is no access (not yet) to the RTC options.
I don't have a MM+ so I can't test with it.


causality ≠ correlation ≠ coincidence
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 06:25pm 08 Jun 2018
Copy link to clipboard 
Print this post

I test for the RTC address having a device first before doing an RTC GETTIME.


I2C open 100, 1000 ' I2C enable at 100kHz with 1000ms time out
I2C read &H68, 0, 1, temp ' 3231 I2C address
IF MM.I2C = 0 Then
RTC GETTIME
EndIf
I2C close

Micromites and Maximites! - Beginning Maximite
 
TrevorH
Senior Member

Joined: 06/04/2018
Location: United Kingdom
Posts: 145
Posted: 07:19pm 08 Jun 2018
Copy link to clipboard 
Print this post

@CircuitGizmos . Thanks for that I will give it a whirl.

Trevor
 
erbp
Senior Member

Joined: 03/05/2016
Location: Australia
Posts: 195
Posted: 01:16am 09 Jun 2018
Copy link to clipboard 
Print this post

I don't know if the following will help, but this is what I use to detect whether the RTC module is present or not on a MX170 which doesn't have an OPTION RTC … command.


SETPin Pin_Brake, Off 'release Pin 18
SetPin Pin_Reverse, Off 'release Pin 17
Pause 50
I2C Open 100, 200 'Open the I2C communication session
Pause 100
On Error Skip 1
RTC GetTime 'Set MM Date & Time from RTC module via I2C
If MM.ERRNO <> 0 then
'RTC not present (or failed to communicate) - Reset RTC_Flag
RTC_Flag = 0
etc. etc.


In this case I am even sharing the I2C pins with other functions and release them before opening the I2C connection and attempting to get the date/time from the RTC module.

I have NOT tried this approach on an E100 using the OPTION RTC … command.

Phil.
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2463
Posted: 04:01am 09 Jun 2018
Copy link to clipboard 
Print this post

  TrevorH said  my program uses the RTC on an E100 board, if I run the program without setting the RTC options, it crashes the PIC32. This forces me to do the multiple !!!!! thing to recover


on the face of it, this behaviour sounds like a bug in the mmbasic firmware. can peter or goeff comment?

cheers,
rob :-)
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 01:35am 11 Jun 2018
Copy link to clipboard 
Print this post

  robert.rozee said  
  TrevorH said  my program uses the RTC on an E100 board, if I run the program without setting the RTC options, it crashes the PIC32. This forces me to do the multiple !!!!! thing to recover


on the face of it, this behaviour sounds like a bug in the mmbasic firmware. can peter or goeff comment?

cheers,
rob :-)

If you do not set the RTC option the RTC GETTIME command will try to use the standard I2C interface and if it cannot find the rtc it will give a message "RTC not responding".

It will not cause the PIC32 to crash. I don't know what is going on here but it is not the RTC command.

Geoff
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