chipKIT® Development Platform

Inspired by Arduino™

Max32 - Do I have a defective board? Cant get IO Working

Created Wed, 04 Dec 2013 01:22:45 +0000 by Dookie454


Dookie454

Wed, 04 Dec 2013 01:22:45 +0000

Hello, wondering if someone could please help or explain this to me? I'm at the end of the road with this Max32 unless I can figure this out.

I got this Max32 board last xmas, I've tried to use it for simple I/O type things... while most of the simple things I've tried (the included examples) seem, or at least seemed to work ok. Anything a little more complex doesn't work.

Couple things I can make work are:

  1. display analog input over serial
  2. Receive a digital input, and invert it and send it out to another output.

I've tried to use it for an analog XYZ accelerometer, but could never get the auto-zero feature to work.... so really just displaying the analog inputs. Other things never could get working so I finally ran out to radio shack and picked up a name brand Arduino Mega... and everything I try with that board works fine.

Now, I thought this code should be plug and play, attached below. It works fine on the Mega, but not on the Max32...

The default status after power up, assuming there is no jumper wire across pin 52 and 53 is 8 outputs grounded, idling in a "all on" state, waiting to hear commands from the serial port. Most of the code you can ignore since I'm having problems with one of the first commands, "TurnLightsON" and sit there idle. I have a standard Sainsmart relay pack. These are connected to the pins labeled 22-29 on both boards (Mega, and Max32). I've tried all the versions of separate power supplies on the sainsmart relay's with the Max32, nothing changes.

With the Mega, all 8 ground, or turn on my relay leds, and run a random loop when pins 52/53 are shorted. With the Max32, same code, I only get a few grounding, with 24 always dim... and shorting 52/53 does nothing... here is the breakdown of the Max32 outputs in this default "all on" state: 22 - LED On 23 - LED On 24 - LED DIM ONLY 25 - LED ON 26 - LED OFF 27 - LED OFF 28 - LED ON 29 - LED ON

I also just updated the bootloader on the Max32 from: Original bootloader version: FFFFFFFF Updated to bootloader version: 1000108

Also used both mpide-0023-windows-20120903 and mpide-0023-windows-20121013-test (the latter with the newer bootloader)

Both do the same thing... which is basically nothing. It's like the "Output" commands to the pins is not correct or something.

// THIS WORKS WITH "Vixen__Example_3_Random or Vixen 20 channels"  THE KEY IS IT WORKS OVER ONLY 1 SERIAL PORT "SERIAL" not "Serial1"
// http://forum.arduino.cc/index.php?PHPSESSID=pbua0s30een47n9ga2sm0s3894&topic=135501.0

// which pins control which channels
#define CHANNEL01  2
#define CHANNEL02  3
#define CHANNEL03  4
#define CHANNEL04  5
#define CHANNEL05  6
#define CHANNEL06  7
#define CHANNEL07  8
#define CHANNEL08  9
#define CHANNEL09  10
#define CHANNEL10  11
#define CHANNEL11  12
#define CHANNEL12  13
#define CHANNEL13  22  // orig was 44
#define CHANNEL14  23  // orig was 45
#define CHANNEL15  24  // orig was 46
#define CHANNEL16  25  // orig was 47

#define CHANNEL17  26  // orig was 44
#define CHANNEL18  27  // orig was 45
#define CHANNEL19  28  // orig was 46
#define CHANNEL20  29  // orig was 47





// Which pins is the random/Vixen mode switch using
#define RANDOM_MODE_PININ 52
#define RANDOM_MODE_PINOUT 53
#define RANDOM_MODE_SPEED 50   // was 100

int channels[] = {CHANNEL01,CHANNEL02,CHANNEL03,CHANNEL04,CHANNEL05,CHANNEL06,CHANNEL07,CHANNEL08,CHANNEL09,CHANNEL10,CHANNEL11,CHANNEL12,CHANNEL13,CHANNEL14,CHANNEL15,CHANNEL16,CHANNEL17,CHANNEL18,CHANNEL19,CHANNEL20};
//for only 8 channels:  int channels[] = {CHANNEL13,CHANNEL14,CHANNEL15,CHANNEL16,CHANNEL17,CHANNEL18,CHANNEL19,CHANNEL20};

// how many channel will vixen be sending
#define CHANNEL_COUNT 20

// speed for the com port for talking with vixen
// Example 3 #define VIXEN_COM_SPEED 9600  //was 57600

// speed for talking with the serial monitor in the IDE
// Example 3 #define PC_COM_SPEED 9600  //was 57600

// setup your choice of dimming values or just on/off values
// the relays don't seem to be able to dim the lights so it looks
// like I will have to build dimmer circuits for next year. The
// doesn't change, just have to remove the relay bord and replace
// it with a dimmer circuit for each relay.
#define MODE_DIMMING 0
#define MODE_FULL 1
#define MODE MODE_FULL

boolean startingVixen = true;




void setup()
{
  Serial.begin(9600);  //VIXEN_COM_SPEED
  //Serial1.begin(VIXEN_COM_SPEED);
  Serial.println("Vixen_Example_3");
  
 
  
  // set the channel pins to output mode
  for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
    pinMode(channels[channelIndex],OUTPUT);
  }
  
  // set up the switch for Vixen or Random mode
  pinMode(RANDOM_MODE_PININ, INPUT);
  digitalWrite(RANDOM_MODE_PININ,HIGH); // turn on the internal pull-up resistor
  pinMode(RANDOM_MODE_PINOUT, OUTPUT);
  
   //turnLightsON();  // Turns everything on after startup to check
  //delay(5000);
  //powerOnSelfTest();
}





// !!!! note the PWM values that need to be sent to the relay board are reversed from the
// values comming in from Vixen.  Vixen 0-255 (off-on), Relays 255-0 (off-on)
void loop()
{
  if(digitalRead(RANDOM_MODE_PININ)==LOW){ // blink at random mode
    startingVixen=true;
    doRandomLights();
  }else{ // play from Vixen mode
    if(startingVixen==true)
      //turnLightsOff();
      turnLightsON();  // this turns things on by default to be able to check things.
    readFromVixen();
  }
}

void powerOnSelfTest()
{
    Serial.println("Vixen_Example_3...... Power on self test running.");
    turnLightsON();
    //for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
      //Serial.print("Channel: ");
      //Serial.println(channelIndex+1,DEC);
      //analogWrite(channels[channelIndex], 0); // turn on one channel at a time
      //delay(2000); // wait .1 seconds
      //analogWrite(channels[channelIndex], 255);
    //}
    //turnLightsOff(); 
}


void turnLightsON()
{
  //turn them all on
  for(int channelIndex=0;channelIndex<12;channelIndex++){
    analogWrite(channels[channelIndex], 255);
  }
  
  for(int channelIndex=12;channelIndex<20;channelIndex++){
    digitalWrite(channels[channelIndex], LOW);
  }
  
  
  
}


void turnLightsOff()
{
  //turn them all off
  for(int channelIndex=0;channelIndex<12;channelIndex++){
    analogWrite(channels[channelIndex], 0);
  }
  
  for(int channelIndex=12;channelIndex<20;channelIndex++){
    digitalWrite(channels[channelIndex], HIGH);
  }
  
  
}

void doRandomLights()
{
    randomSeed(analogRead(0));
    // Example 3   Serial.println("Writting random values.");
    for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
      if(MODE == MODE_DIMMING)
      {
        int randNumber = random(255);
        randNumber = map(randNumber, 0, 255, 255, 0);
        analogWrite(channels[channelIndex], randNumber);
        //Serial.print(randNumber, DEC);
        //Serial.print(",");
      }
      else // not dimming, just on or off
      {
        int randNumber = random(0, 255);
        randNumber = map(randNumber, 0, 255, 255, 0);
        if(randNumber<=128)
          analogWrite(channels[channelIndex], 0);
        else
          analogWrite(channels[channelIndex], 255);
        //Serial.print(randNumber, DEC);
        //Serial.print(",");
      }
    }
    //Serial.println("");
    delay(random(50,RANDOM_MODE_SPEED));   // was 100
}

void outputToLights(unsigned char* buffer)
{
    for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
      analogWrite(channels[channelIndex], buffer[channelIndex]);
      //Serial.print(buffer[channelIndex], DEC);
      //Serial.print(",");
    }
    //Serial.println("");
}

void readFromVixen()
{
  //Serial.println("Waiting for data from Vixen.");
  startingVixen = false;
  char *footer="VIXEN_END";
  unsigned char buffer[CHANNEL_COUNT];
  char buffer2[CHANNEL_COUNT];
  int index=0;
  unsigned long time = millis();

  waitForVixenHeader();
  while (true) {
    int inByte = Serial.read();
    if(inByte==-1){
      if(index==0 && millis()-time>1000) // we haven't read anything in a second
        return;
      continue;
    }
    time = millis();
    int lightByte = map(inByte, 0, 255, 255, 0);
    buffer[index] = lightByte;
    buffer2[index] = inByte;
    buffer[index+1] = 0;
    buffer2[index+1] = 0;
    index++;
    if(index==9 && strcmp(footer,buffer2)==0){
      //Serial.println(footer);
      return;
    }
    else if(index==CHANNEL_COUNT){
      outputToLights(buffer);
      index=0;
    }
  }
  //Serial.println("");
}

void waitForVixenHeader()
{
  char *header="VIXEN_START";
  char buffer[12];
  int index = 0;
  unsigned long time = millis();

  while (true) {
  int inByte = Serial.read();  // was Serial1
    if(inByte==-1){
      if(index==0 && millis()-time>1000) // we haven't read anything in a second
        return;
      continue;
    }
    time = millis();
    buffer[index] = inByte;
    if(buffer[index]!=header[index]) {// not the right sequence restart
      index=-1;
    }
    buffer[index+1] = 0; // add null
    index++;
    if(index==11 && strcmp(header,buffer)==0){
      //Serial.println(header);
      return;
    }
  }
}

majenko

Thu, 19 Dec 2013 23:40:59 +0000

With the Max32, same code, I only get a few grounding, with 24 always dim... and shorting 52/53 does nothing... here is the breakdown of the Max32 outputs in this default "all on" state: 22 - LED On 23 - LED On 24 - LED DIM ONLY 25 - LED ON 26 - LED OFF 27 - LED OFF 28 - LED ON 29 - LED ON

Pins 26 and 27 can only be used as inputs, then can't be configured as outputs. This is because they are shared with the USB peripheral (D+ and D- lines).

Pin 24 is the VBUS pin of the USB peripheral. According to the MAX32 reference manual:

Pin 24 (VBUS) can be used by a self powered USB device to monitor the presence of bus voltage on the USB bus. This pin on the PIC32 microcontroller is an analog input pin used by the USB controller, and is not useable as a user I/O pin even when not using the USB controller.

Pins 52 and 53 form part of the SPI port, and their function is modified by the jumpers J3 and J4. Try changing the jumpers to see if that has an effect.