chipKIT® Development Platform

Inspired by Arduino™

dmx avr

Created Sat, 15 Oct 2011 07:53:48 +0000 by kasperkamperman


kasperkamperman

Sat, 15 Oct 2011 07:53:48 +0000

Hi,

I try to port some AVR code to the Chipkit Uno32. However I'm not really into AVRs, PICs etc. I've browsed this forum a bit, but I don't really get how to convert pinmappings etc. for another chip.

Is there a good tutorial on this, that also explains the basics so I can convert something? Most resources assume that you all already familiar with AVR lowlevel programming and syntax.

I'm not looking for some Noob programming explanation but just some details for average c++/c programmers.

The errors:

/Applications/Mpide.app/Contents/Resources/Java/hardware/pic32/cores/pic32/pins_arduino.h:84:14: error: 'uint32_t' does not name a type
/Applications/Mpide.app/Contents/Resources/Java/hardware/pic32/cores/pic32/pins_arduino.h:85:14: error: 'uint32_t' does not name a type
/Applications/Mpide.app/Contents/Resources/Java/hardware/pic32/cores/pic32/pins_arduino.h:86:14: error: 'uint32_t' does not name a type
/Applications/Mpide.app/Contents/Resources/Java/hardware/pic32/cores/pic32/pins_arduino.h:87:14: error: 'uint8_t' does not name a type
/Applications/Mpide.app/Contents/Resources/Java/hardware/pic32/cores/pic32/pins_arduino.h:89:14: error: 'uint8_t' does not name a type
/Applications/Mpide.app/Contents/Resources/Java/hardware/pic32/cores/pic32/pins_arduino.h:92:14: error: 'uint16_t' does not name a type
/Applications/Mpide.app/Contents/Resources/Java/hardware/pic32/cores/pic32/pins_arduino.h:93:14: error: 'uint8_t' does not name a type
triklits_serialconnect_ard16.cpp:11:22: error: '_SFR_IO_ADDR' was not declared in this scope
triklits_serialconnect_ard16.cpp:12:22: error: '_SFR_IO_ADDR' was not declared in this scope
triklits_serialconnect_ard16.cpp:13:22: error: '_SFR_IO_ADDR' was not declared in this scope
triklits_serialconnect_ard16.cpp: In function 'void sendFrame()':
triklits_serialconnect_ard16.cpp:23:35: error: 'digital_pin_to_port_PGM' was not declared in this scope
triklits_serialconnect_ard16.cpp:24:17: error: 'digital_pin_to_bit_mask_PGM' was not declared in this scope
triklits_serialconnect_ard16.cpp:32:53: error: '_SFR_IO8' was not declared in this scope
triklits_serialconnect_ard16.cpp:32:54: error: '_SFR_BYTE' was not declared in this scope
triklits_serialconnect_ard16.cpp:33:53: error: '_SFR_IO8' was not declared in this scope
triklits_serialconnect_ard16.cpp:33:54: error: '_SFR_BYTE' was not declared in this scope
triklits_serialconnect_ard16.cpp:49:56: error: '_SFR_IO8' was not declared in this scope
triklits_serialconnect_ard16.cpp:49:57: error: '_SFR_BYTE' was not declared in this scope
triklits_serialconnect_ard16.cpp:50:56: error: '_SFR_IO8' was not declared in this scope
triklits_serialconnect_ard16.cpp:50:57: error: '_SFR_BYTE' was not declared in this scope
triklits_serialconnect_ard16.cpp:55:55: error: '_SFR_IO8' was not declared in this scope
triklits_serialconnect_ard16.cpp:55:56: error: '_SFR_BYTE' was not declared in this scope
triklits_serialconnect_ard16.cpp:56:55: error: '_SFR_IO8' was not declared in this scope
triklits_serialconnect_ard16.cpp:56:56: error: '_SFR_BYTE' was not declared in this scope
triklits_serialconnect_ard16.cpp:61:55: error: '_SFR_IO8' was not declared in this scope
triklits_serialconnect_ard16.cpp:61:56: error: '_SFR_BYTE' was not declared in this scope
triklits_serialconnect_ard16.cpp:62:55: error: '_SFR_IO8' was not declared in this scope
triklits_serialconnect_ard16.cpp:62:56: error: '_SFR_BYTE' was not declared in this scope
triklits_serialconnect_ard16.cpp:67:55: error: '_SFR_IO8' was not declared in this scope
triklits_serialconnect_ard16.cpp:67:56: error: '_SFR_BYTE' was not declared in this scope
triklits_serialconnect_ard16.cpp:68:55: error: '_SFR_IO8' was not declared in this scope
triklits_serialconnect_ard16.cpp:68:56: error: '_SFR_BYTE' was not declared in this scope
triklits_serialconnect_ard16.cpp:78:32: error: '_SFR_IO8' was not declared in this scope
triklits_serialconnect_ard16.cpp:78:33: error: '_SFR_BYTE' was not declared in this scope
triklits_serialconnect_ard16.cpp: In function 'void loop()':
triklits_serialconnect_ard16.cpp:115:9: error: 'cli' was not declared in this scope
triklits_serialconnect_ard16.cpp:117:9: error: 'sei' was not declared in this scope

The code (wanted to attach the file but the .pde extension is not allowed... and .txt neither (tried to rename).

#include "pins_arduino.h"

int triklitsPin = 3;  
int port_to_output[] = {
   NOT_A_PORT,
   NOT_A_PORT,
   _SFR_IO_ADDR(PORTB),
   _SFR_IO_ADDR(PORTC),
   _SFR_IO_ADDR(PORTD)
   };

#define ARRAYLENGTH 24*3
int intensity_Array[ARRAYLENGTH];
int arraylength=ARRAYLENGTH;

// ----------------------------------------------------------

void sendFrame()
{ int portNumber = port_to_output[digitalPinToPort(triklitsPin)];
  int pinMask = digitalPinToBitMask(triklitsPin);
  
  byte header = B0100; // reversed by loop to B0010
  byte mask; 
  
  // header 0010 --------------------------------  
    
  for (int count = 0; count < 4; count++) 
  { if (header & 0x01) _SFR_BYTE(_SFR_IO8(portNumber)) |= pinMask;
    else               _SFR_BYTE(_SFR_IO8(portNumber)) &= ~pinMask; // 0
    header>>=1; 
    delayMicroseconds(22);
    asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n");  
  }   
  
  // RGB data 24 * 32 bits-----------------------
    
  for(int i=0;i<24;i++)
  { int count=i*3;  
    int r_Byte=intensity_Array[count]; //;intensity_Array[count*3];
    int g_Byte=intensity_Array[count+1];//intensity_Array[count];//=intensity_Array[(count*3)+1];
    int b_Byte=intensity_Array[count+2];//=intensity_Array[(count*3)+2];   
  
    // send interlaced RGB data for 1 light
    for (mask = 0x01; mask>0; mask <<= 1)
    { if (r_Byte & mask)  _SFR_BYTE(_SFR_IO8(portNumber)) |= pinMask;  // 1
      else                _SFR_BYTE(_SFR_IO8(portNumber)) &= ~pinMask; // 0
    
      delayMicroseconds(22);
      asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
    
      if (g_Byte & mask) _SFR_BYTE(_SFR_IO8(portNumber)) |= pinMask;  // 1
      else               _SFR_BYTE(_SFR_IO8(portNumber)) &= ~pinMask; // 0
    
      delayMicroseconds(22);
      asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
        
      if (b_Byte & mask) _SFR_BYTE(_SFR_IO8(portNumber)) |= pinMask;   // 1
      else               _SFR_BYTE(_SFR_IO8(portNumber)) &= ~pinMask;  // 0 
       
      delayMicroseconds(22);
      asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
   
      if (b_Byte & mask) _SFR_BYTE(_SFR_IO8(portNumber)) &= ~pinMask; // 0
      else               _SFR_BYTE(_SFR_IO8(portNumber)) |= pinMask;  // 1 // p is opposite of b   
    
      delayMicroseconds(22);
      asm("nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
    
      //delayMicroseconds(16); // shorter because calculation at start.. it works...
    }    
  }
  
  // send trailer bit 0
  _SFR_BYTE(_SFR_IO8(portNumber)) &= ~pinMask; 
  delayMicroseconds(10);
}

// ---------------------------------------------------------------------------

void setup() 
{ pinMode(triklitsPin, OUTPUT);
  Serial.begin(57600); 
}

byte ledNum; 
byte redVal; 
byte grnVal; 
byte bluVal;  

int arrayStartPos;

void loop()
{ if( Serial.available() == 4 ) {
    ledNum = Serial.read();
    redVal = Serial.read();
    grnVal = Serial.read();
    bluVal = Serial.read();
    
    arrayStartPos = ledNum*3;
    
    intensity_Array[arrayStartPos]   = redVal;
    intensity_Array[arrayStartPos+1] = grnVal;
    intensity_Array[arrayStartPos+2] = bluVal;
  }
  
  if(ledNum==22) 
  { ledNum=0; // set the ledNum to the beginning
    
    /* send frame to led data */
    cli();    
    sendFrame(); 
    sei();
  }
   
}

kasperkamperman

Tue, 18 Oct 2011 08:48:09 +0000

Mmm, chipKIT doesn't seem so alive as the Arduino community itself and the forum is to restrictive to new users. Can't even link to in site URL's (notification says: "Your post looks too spamy for a new user, please remove off-site URLs.") when I link to another question post.

This question is the same as mine: DigitalWriteFast library for Uno32?

Would like to have more information about direct port manipulation, since a lot of great Arduino libraries make use of this.


meistro

Wed, 23 Nov 2011 01:19:29 +0000

Anyone? I would like to know this too. Not much fun when I can't figure out how to blink an led. I need to know what to call the pin I'm trying to use.

Thanks


Jacob Christ

Fri, 25 Nov 2011 00:10:07 +0000

. The errors:

/Applications/Mpide.app/Contents/Resources/Java/hardware/pic32/cores/pic32/pins_arduino.h:84:14: error: 'uint32_t' does not name a type
s_arduino.h:93:14: error: 'uint8_t' does not name a type

These errors are due the not including stdint.h which is a cross platform ctypes like file for defining types based on the number of bits needed (rather than the size of the data bus)

Jacob