Jump to content
43oh

5529 sets an output before setup()


Recommended Posts

G'day, some port bits get set before the setup() can clear them. The same condition happens with the Blink sketch.

The first lines in setup() are

P6DIR = 0xFF;

P6OUT = 0x0;

P3DIR = 0xFF;

P3OUT = 0x0;

And after setup() has run the outputs are correct and the sketch works 100%

 

But for a brief moment before setup() runs for the first(and only time) I get a few bits set on the port.

Normally it would not matter but the ports are used to vary the volume and I get a thump each time I switch on.

 

Also when reset switch is pressed (and held down)the same port bits switch high

 

My thoughts is that I have a crook 5529, and will replace it as soon as I get a new one.

Link to post
Share on other sites

It's not an Energia thing, but more an MSP thing, and is relatively common with any MCU.

 

Pin state on power up is indeterminate: they may come up in any one of three states- low, high or floating between.

 

If you need to have an absolute known state when powering up, consider adding pull up or down resistors to the circuit / pins. These may be relatively high values such as 10-100K ohm or so, so that the pin can override the pull up/down resistor easily.

Link to post
Share on other sites

G'day,

I think the clue to the problem is what is happening when the reset switch is depressed, and held.

I get a square wave on P3.0, P3.1, P3.3 and P3.4

To my way of thinking this eliminates any funny problems that may be caused by the sketch, as the MSP is held in the reset state.

Is this assumption correct?

Will find out what the frequency is when I get back home (only have a logic probe at the moment)

 

I put 10K pull down resistors on these o/p's and is made no difference.

Link to post
Share on other sites

Have eliminated a few fault areas, regarding O/P's oscillating when reset button kept depressed.

Not the 5529 as it's been replaced.

Not the defines etc before the setup() as I inserted it into Blink sketch and all o/p went to zero

Not the code in the setup() (wouldn't expect it to be anyway) as I also inserted it into Blink sketch and all o/p went to zero

So what is left... have no idea.

Link to post
Share on other sites

Not the defines etc before the setup() as I inserted it into Blink sketch and all o/p went to zero

Not the code in the setup() (wouldn't expect it to be anyway) as I also inserted it into Blink sketch and all o/p went to zero

What do you mean with "Blick sketch and all o/p went to zero"? That you don't observe the strange reset behavior with Blink?

 

If so, it would be helpful to know what else you do in the sketch.

Link to post
Share on other sites

 

 

I'm using the following Libs:-

#include "MspFlash.h"

#include "IRremote.h"

#include "LiquidCrystal.h"

#include "rgb_lcd.h"

#include <Wire.h>

#include <FRAMX.h>

#include <SoftwareSerial.h>

When I copy the setup() code, plus the defines code before setup(), from the project into the Blink sketch THEN press and hold the Reset button, I see no errant outputs, e.g. All Port 3 O/P are zero (as you would expect).

The pulsing on the P3 pins (in the project sketch) also happens when the Sketch is first launched, before setup() and Main() code is run.

Hope this data helps.

Grant

The new blink code has all the code from my Project sketch except code in Main().

Link to post
Share on other sites

Good idea, will start checking the Lib's.

Would be nice to know actually what happens when the reset switch is held depressed.

Have added the code that I use before the setup().

 

P.S. what is the best way to display code, I used  "Quote" but it spans many lines.

 

 

 

const char Sketch[]="AjonFlash20 ";
const String BTADDR1="+ADDR:2013:9:11";  // this is BT #3
//From bildr article: http://bildr.org/2012/08/rotary-encoder-arduino/

#define intest 0    // no test
//#define intest 1    // in test
#define test 0    // no test
//#define test 1  // Serial.print state and choice
#include "MspFlash.h"
#include "IRremote.h"
#include "LiquidCrystal.h"
#include "rgb_lcd.h"
#include <Wire.h>
#include <FRAMX.h>
//#include <SoftwareSerial.h>
//#define BT_TX 39
//#define BT_RX 40
//#define BT_KEY 38
//boolean GFuseold=true;

#define bannerLength 72
#define MAXIR        22     // number of buttons on IR controller
#define MAXTEXT       6     //number of inputs requiring Text
#define MAXDEFINES    9     // now includes balance(Left/Right)Offset and mmStatus. Defines used in FRAM stating at 0x10
#define USESMALL     true   // true  for SMALL vero card //#define USESMALL false for LARGE vero card
#define greenLED     12     //6apr2015 P2_7 //was P7_4  //=17  // was 9 moved to allow link
#define blueLED      P2_6  //=13  // was 8
#define output1      P1_4 //apr15 WAS #define output1      P3_5
#define output2      P1_5 //apr15 WAS #define output2      P3_6
#define output3      P4_0
#define output4      P8_2
#define output5      P7_0
#define output6      P2_4 //apr15 WAS #define output6      P3_7
#define power        P2_5 //apr15 WAS #define power        P3_2  //P6_6   // was P3_7
#define mute         P8_1  //apr2015 was P6_6
#define fetPin       P1_3
#define linkOut      P7_4
#define linkIn       P1_4
#define pinMM        P2_6
#define LEDRATE 400
#define w  0  //white
#define r  1  //red
#define g  2  //green
#define b  3  //blue
#define p  4  //pale blue
#define y  5  //yellow
#define v  6  //violet
#if USESMALL // SMALL vero
  #define encoderPin1      19   //was 2;
  #define encoderPin2      18   //was 3;
  //6apr2015
  #define encoderSwitchPin 8 //6apr2015 WAS P2_3 //12  //push button switch
  #define RECV_PIN         P1_6   //was 6
#else  //BIG vero
#endif
boolean mytest=true;
boolean doingBalance=false;
boolean mmStatus=true;
boolean muteState=true;
String  sData;
//SoftwareSerial BTSerial(BT_RX,BT_TX); //Bluetooth  RX | TX

//Initialize the FRAM and use the default FRAM address that's provided
FRAMX fram(FRAMX::FRAMX_I2C_DEFAULT_ADDRESS);
unsigned char bytes_read;
//Initialize to known data so we can tell if transactions are actually having the desired effect
static unsigned char read_buffer[10] ={0xDE,0xAD,0xBE,0xEF,0xDE,0xAD,0xBE,0xEF,0xAA,0xAA};
static unsigned char write_buffer[10]={0xDE,0xAD,0xBE,0xEF,0xDE,0xAD,0xBE,0xEF,0xAA,0xAA};
unsigned char start_address = 0;
unsigned char bytes_to_transfer = 1; // do not exceed the length of your read and write buffer
unsigned long readcodes[16];
unsigned long FetMute;
uint32_t framIr[MAXIR];           //IR codes from FRAM0   0x20
uint8_t  framChr[MAXIR];          //IR Chr code from FRAM 0x20
String   framText[6];             // Text from FRAM       0xB0
uint8_t  framDefines[MAXDEFINES]; //Defines from Fram     0x10

int16_t  countLast=0;
int16_t  countNow=0;
uint8_t  aBalance=0, bBalance=0;
uint8_t  balanceRightOffset=0;
uint8_t  balanceLeftOffset=0;
uint16_t balanceDefault=0x3F;

String sVersion;
String EEwrite;
String sTemp;
char   cTemp;
int8_t iTemp;
int8_t jTemp;
char   cArray[]={"        "}; 
uint8_t i;
uint8_t j;
char cmdNum;
int inByte = 0;         // incoming serial byte

#define sMenu0 "Grant 0422179043"  // was const char sMenu0[]={"Grant 0422179043"};
#define blankLine "                "
char sInputSelect0[]={"Input Select    "};
char sInputSelect1[]={"123456          "};
char work;
unsigned int state   =  0;
char         inputIs =  0;
volatile int lastEncoded   = 3;
volatile long encoderValue = 0;
long lastValue;
unsigned int encoderSteps  = 16;  //used for altering LCD back light
long startTime        = 0;
long lastencoderValue = 0;
long l;
unsigned int encoderPWM;
unsigned int encoderVolume;
boolean ledState = true;
boolean redState   = 1;  // Led Off
boolean greenState = 1;  // Led Off
boolean blueState  = 1;  // Led Off

boolean pollEncoder =false;

int lastMSB = 0;
int lastLSB = 0;

long previousMillis = 0;
long currentMillis;
boolean doPrint=false;
int8_t choice=-1;
boolean LedState=false;
//int RECV_PIN = 6;  //11;
unsigned long myvalue;

IRrecv irrecv(RECV_PIN);
decode_results results;

boolean IRcommand =false;
byte IRgot;
boolean doText =false;  //construct words
unsigned int mycount=0;
rgb_lcd lcd;
unsigned int mode =0;
boolean haveData=false;
boolean haveData4=false;
int EEinputs=6;  //=5;
int EEsteps=2;   //=3;
int EEstepsTest=1;  //EEsteps=EEstepsTest; //6apr2015 WAS
uint16_t EElight=80;
uint8_t EEvolume[6] ;  //={10,20,30,40,50};
unsigned long EEscale[9] ;
uint8_t EElastInput=0;
uint8_t EEpwm=0xFF;

byte square[8] = {  // make some custom characters:
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b00000,
  0b00000
};
byte filler[8] = {  // make some custom characters:
  0b00000,
  0b00000,
  0b00000,
  0b10101,
  0b10101,
  0b00000,
  0b00000,
  0b00000
};
  char    lastDecode;
  boolean doOnce;
  boolean powerUp = true;
  boolean allowIRcommands;
 
  unsigned int redPWM  = 255;
  unsigned int greenPWM= 255;
  unsigned int bluePWM = 255;
 
  boolean doOnceMute=false;
  boolean lcdSleep=false;
 
  unsigned long lcdPreviousMillis;
  unsigned long lcdTimeout;
  boolean doLCDsleepTest = true;
  uint8_t EEtimeout;
  int LCDred;
  int LCDgreen;
  int LCDblue; 
  //6apr2015
  boolean sleepingNew = false;
  int ii;
  int EEstepsTemp;
  int EEstepsOrg;
  char irDirect = ' ';
 
  boolean copyToIrFram     = false;
  boolean copyToTextFram   = false;
  boolean copyToDefinesFram= false;
  boolean dimIt            = false;
  boolean doTimeOutTest; // if false never turn off LCD
  boolean linkTest         = false;

///////////////////////////////////////////////////////////////////

Link to post
Share on other sites

Well have cut out all the sketch #includes namely:
  #include "MspFlash.h"
  #include "IRremote.h"
  #include "LiquidCrystal.h"
  #include "rgb_lcd.h"
  #include <Wire.h>
  #include <FRAMX.h>

And still get the offending outputs High when the reset button held depressed.

 

So now at a complete loss....
 

Link to post
Share on other sites

Good idea, will start checking the Lib's.

Would be nice to know actually what happens when the reset switch is held depressed.

Have added the code that I use before the setup().

 

P.S. what is the best way to display code, I used  "Quote" but it spans many lines.

"CODE" tags- the button in the advanced editor ("More Reply Options") with "<>" on it, or manually type in [ CODE] and [ /CODE], without any space after the opening brace.

const char Sketch[]="AjonFlash20 ";
 const String BTADDR1="+ADDR:2013:9:11";  // this is BT #3
 //From bildr article: http://bildr.org/201...ncoder-arduino/

#define intest 0    // no test
 //#define intest 1    // in test
 #define test 0    // no test
 //#define test 1  // Serial.print state and choice
 #include "MspFlash.h"
 #include "IRremote.h"
 #include "LiquidCrystal.h"
 #include "rgb_lcd.h"
 #include <Wire.h>
 #include <FRAMX.h>
 //#include <SoftwareSerial.h>
 //#define BT_TX 39
 //#define BT_RX 40
 //#define BT_KEY 38
 //boolean GFuseold=true;

#define bannerLength 72
 #define MAXIR        22     // number of buttons on IR controller
 #define MAXTEXT       6     //number of inputs requiring Text
 #define MAXDEFINES    9     // now includes balance(Left/Right)Offset and mmStatus. Defines used in FRAM stating at 0x10
 #define USESMALL     true   // true  for SMALL vero card //#define USESMALL false for LARGE vero card
 #define greenLED     12     //6apr2015 P2_7 //was P7_4  //=17  // was 9 moved to allow link
 #define blueLED      P2_6  //=13  // was 8
 #define output1      P1_4 //apr15 WAS #define output1      P3_5
 #define output2      P1_5 //apr15 WAS #define output2      P3_6
 #define output3      P4_0
 #define output4      P8_2
 #define output5      P7_0
 #define output6      P2_4 //apr15 WAS #define output6      P3_7
 #define power        P2_5 //apr15 WAS #define power        P3_2  //P6_6   // was P3_7
 #define mute         P8_1  //apr2015 was P6_6
 #define fetPin       P1_3
 #define linkOut      P7_4
 #define linkIn       P1_4
 #define pinMM        P2_6
 #define LEDRATE 400
 #define w  0  //white
 #define r  1  //red
 #define g  2  //green
 #define b  3  //blue
 #define p  4  //pale blue
 #define y  5  //yellow
 #define v  6  //violet
 #if USESMALL // SMALL vero
   #define encoderPin1      19   //was 2;
   #define encoderPin2      18   //was 3;
   //6apr2015
   #define encoderSwitchPin 8 //6apr2015 WAS P2_3 //12  //push button switch
   #define RECV_PIN         P1_6   //was 6
 #else  //BIG vero
 #endif
 boolean mytest=true;
 boolean doingBalance=false;
 boolean mmStatus=true;
 boolean muteState=true;
 String  sData;
 //SoftwareSerial BTSerial(BT_RX,BT_TX); //Bluetooth  RX | TX

//Initialize the FRAM and use the default FRAM address that's provided
 FRAMX fram(FRAMX::FRAMX_I2C_DEFAULT_ADDRESS);
 unsigned char bytes_read;
 //Initialize to known data so we can tell if transactions are actually having the desired effect
 static unsigned char read_buffer[10] ={0xDE,0xAD,0xBE,0xEF,0xDE,0xAD,0xBE,0xEF,0xAA,0xAA};
 static unsigned char write_buffer[10]={0xDE,0xAD,0xBE,0xEF,0xDE,0xAD,0xBE,0xEF,0xAA,0xAA};
 unsigned char start_address = 0;
 unsigned char bytes_to_transfer = 1; // do not exceed the length of your read and write buffer
 unsigned long readcodes[16];
 unsigned long FetMute;
 uint32_t framIr[MAXIR];           //IR codes from FRAM0   0x20
 uint8_t  framChr[MAXIR];          //IR Chr code from FRAM 0x20
 String   framText[6];             // Text from FRAM       0xB0
 uint8_t  framDefines[MAXDEFINES]; //Defines from Fram     0x10

int16_t  countLast=0;
 int16_t  countNow=0;
 uint8_t  aBalance=0, bBalance=0;
 uint8_t  balanceRightOffset=0;
 uint8_t  balanceLeftOffset=0;
 uint16_t balanceDefault=0x3F;

String sVersion;
 String EEwrite;
 String sTemp;
 char   cTemp;
 int8_t iTemp;
 int8_t jTemp;
 char   cArray[]={"        "}; 
 uint8_t i;
 uint8_t j;
 char cmdNum;
 int inByte = 0;         // incoming serial byte

#define sMenu0 "Grant 0422179043"  // was const char sMenu0[]={"Grant 0422179043"};
 #define blankLine "                "
 char sInputSelect0[]={"Input Select    "};
 char sInputSelect1[]={"123456          "};
 char work;
 unsigned int state   =  0;
 char         inputIs =  0;
 volatile int lastEncoded   = 3;
 volatile long encoderValue = 0;
 long lastValue;
 unsigned int encoderSteps  = 16;  //used for altering LCD back light
 long startTime        = 0;
 long lastencoderValue = 0;
 long l;
 unsigned int encoderPWM;
 unsigned int encoderVolume;
 boolean ledState = true;
 boolean redState   = 1;  // Led Off
 boolean greenState = 1;  // Led Off
 boolean blueState  = 1;  // Led Off

boolean pollEncoder =false;

int lastMSB = 0;
 int lastLSB = 0;

long previousMillis = 0;
 long currentMillis;
 boolean doPrint=false;
 int8_t choice=-1;
 boolean LedState=false;
 //int RECV_PIN = 6;  //11;
 unsigned long myvalue;

IRrecv irrecv(RECV_PIN);
 decode_results results;

boolean IRcommand =false;
 byte IRgot;
 boolean doText =false;  //construct words
 unsigned int mycount=0;
 rgb_lcd lcd;
 unsigned int mode =0;
 boolean haveData=false;
 boolean haveData4=false;
 int EEinputs=6;  //=5;
 int EEsteps=2;   //=3;
 int EEstepsTest=1;  //EEsteps=EEstepsTest; //6apr2015 WAS
 uint16_t EElight=80;
 uint8_t EEvolume[6] ;  //={10,20,30,40,50};
 unsigned long EEscale[9] ;
 uint8_t EElastInput=0;
 uint8_t EEpwm=0xFF;

byte square[8] = {  // make some custom characters:
   0b00000,
   0b00000,
   0b11111,
   0b11111,
   0b11111,
   0b11111,
   0b00000,
   0b00000
 };
 byte filler[8] = {  // make some custom characters:
   0b00000,
   0b00000,
   0b00000,
   0b10101,
   0b10101,
   0b00000,
   0b00000,
   0b00000
 };
   char    lastDecode;
   boolean doOnce;
   boolean powerUp = true;
   boolean allowIRcommands;
  
   unsigned int redPWM  = 255;
   unsigned int greenPWM= 255;
   unsigned int bluePWM = 255;
  
   boolean doOnceMute=false;
   boolean lcdSleep=false;
  
   unsigned long lcdPreviousMillis;
   unsigned long lcdTimeout;
   boolean doLCDsleepTest = true;
   uint8_t EEtimeout;
   int LCDred;
   int LCDgreen;
   int LCDblue; 
   //6apr2015
   boolean sleepingNew = false;
   int ii;
   int EEstepsTemp;
   int EEstepsOrg;
   char irDirect = ' ';
  
   boolean copyToIrFram     = false;
   boolean copyToTextFram   = false;
   boolean copyToDefinesFram= false;
   boolean dimIt            = false;
   boolean doTimeOutTest; // if false never turn off LCD
   boolean linkTest         = false;

///////////////////////////////////////////////////////////////////
Link to post
Share on other sites

Thanks @@abecedarian :)
 
My top candidates for premature pin-wiggling:

FRAMX fram(FRAMX::FRAMX_I2C_DEFAULT_ADDRESS);
..
IRrecv irrecv(RECV_PIN);
decode_results results;
..
rgb_lcd lcd;

It's really poking in the dark right now.. do you already have a working application that uses all those libraries?

 

Generally, it's better to start with a simple program, and then step by step build functionality and add libraries as you go along. Verifying at each step that everything you did so far behaves as expected. Otherwise you end up with a big hairy ball with no idea about which side is up, what is broken and why it worked in the first place. Debugging in such a situation will be very time consuming and frustrating.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...