Retain Variables are stored in MRAM, a total of 4KByte is available. These variables will survive power cycles however not reprogramming cycles.
Use the standard declaration VAR RETAIN to define the variables.
MySetpoint : UINT;
In this example a J1939 CAN setpoint message is sent to the uControl, if the Update command is set then the retained variable is updated with the new value in the CAN message.
A separate J1939 CAN message is continually broadcast containing the current value of the retained variable. To test this, update the variable then power cycle the controller and observe the new value has been retained. Reprogram the controller and see the value has been cleared. See notes in the program for more details.
NOTE: Although MRAM has potentially unlimited write cycles for best practices and code portability the variable should only be updated if its value changes.