Go Down

Topic: Custom SAMD51 Board (Add pins in variant files) Issue (Read 2806 times) previous topic - next topic

S1buell

I have created a custom SAMD51 board everything is working good so far.....

Now I connected some of the unused pins to test points to see if I could get them up and running

The pins PB04,5,6,7 (Attached). MCU is ATSAMD51J20A-AU


To start with I was trying to connect PB04 first

Manual reference
http://ww1.microchip.com/downloads/en/DeviceDoc/SAMD21-Family-DataSheet-DS40001882D.pdf
 
PB04 VDDANA EXTINT[4] AIN[12] AIN[0]


I copied the  1.6.2 variant files from the Arduino51 area to work with. I want to bring these pins on as simple analog pins. I will us the PB04 pin to read battery voltage. The other are simple High/Low to turn on power sources etc.

So I opened the variant.h file and the variant.ccp files. THese are the changes I made


Variant.h

// Number of pins defined in PinDescription array
#define PINS_COUNT           (37u)  //Changed from 36 to 37
#define NUM_DIGITAL_PINS     (20u)
#define NUM_ANALOG_INPUTS    (7u)  // Changed from 6 to 7
#define NUM_ANALOG_OUTPUTS   (1u)
#define analogInputToDigitalPin(p)  ((p < 7u) ? (p) + 14u : -1) //change from 6u to 7u

* Analog pins
 */
#define PIN_A0               (14ul)
#define PIN_A1               (PIN_A0 + 1)
#define PIN_A2               (PIN_A0 + 2)
#define PIN_A3               (PIN_A0 + 3)
#define PIN_A4               (PIN_A0 + 4)
#define PIN_A5               (PIN_A0 + 5)
#define PIN_A6               (PIN_A0 + 6) //added

#define PIN_DAC0             (14ul)
#define PIN_DAC1             PIN_A1

static const uint8_t A0  = PIN_A0;
static const uint8_t A1  = PIN_A1;
static const uint8_t A2  = PIN_A2;
static const uint8_t A3  = PIN_A3;
static const uint8_t A4  = PIN_A4;
static const uint8_t A5  = PIN_A5;
static const uint8_t A6  = PIN_A6; //added this line

variant.ccp

// 14..19 - Analog pins
  // --------------------
  { PORTA,  2, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 },
  { PORTB,  4, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel12, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, //Added this line
  { PORTB,  8, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel2, TC4_CH0, TC4_CH0, EXTERNAL_INT_8 },
  { PORTB,  9, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel3, TC4_CH1, TC4_CH1, EXTERNAL_INT_9 },
  { PORTA,  4, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel4, TC0_CH0, TC0_CH0, EXTERNAL_INT_6 },
  { PORTA,  5, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel5, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 },
  { PORTB,  2, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel14, TC6_CH0, TC6_CH0, EXTERNAL_INT_2 },


After I load these new files and run the blink code everything compiles correct but A6/PB4 never blinks the led....

Anyone have a bit more experience in this area and could shed some light on why this does not work?

Thanks.
T


pert

The Arduino pin number is the index of the g_APinDescription array. Since A6 is Arduino pin number 20 (14 + 6), you should have added that line to variant.cpp as the 20th element of the array definition. But you added it at the 15th position. So right now if you blink Arduino pin 15 then PB04 should blink. If you want it to work as A6/20 then you need to move the line to the correct position in the array definition.

S1buell

Ok Im with you...

Where do I find this mapping "Since A6 is Arduino pin number 20 (14 + 6)"


Ok so under the const PinDescription g_APinDescription[]=

I have made the changes.

// 14..20 - Analog pins changed 19 to 20
  // --------------------
  { PORTA,  2, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 },
  { PORTB,  8, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel2, TC4_CH0, TC4_CH0, EXTERNAL_INT_8 },
  { PORTB,  9, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel3, TC4_CH1, TC4_CH1, EXTERNAL_INT_9 },
  { PORTA,  4, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel4, TC0_CH0, TC0_CH0, EXTERNAL_INT_6 },
  { PORTA,  5, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel5, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 },
  { PORTB,  2, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel14, TC6_CH0, TC6_CH0, EXTERNAL_INT_2 },
  { PORTB,  4, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel12, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, //Added this line, Line 20

I will do some testing but I'm worried this will alter my I2C pins

When I make these changes all locations pin mapping with change no? I Did notice "23" in the pin array is not here

// 20..21 I2C pins (SDA/SCL) // These pins in the array will no change no?
  // ----------------------
  { PORTA, 22, PIO_SERCOM, PIN_ATTR_PWM_G, No_ADC_Channel, TC4_CH0, TC4_CH0, EXTERNAL_INT_6 }, // SDA: SERCOM3/PAD[0]
  { PORTA, 23, PIO_SERCOM, PIN_ATTR_PWM_G, No_ADC_Channel, TC4_CH1, TC4_CH1, EXTERNAL_INT_7 }, // SCL: SERCOM3/PAD[1]

  // 22..24 - SPI pins (MISO,MOSI,SCK)
  // ----------------------
  { PORTB, 11, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_11 }, // MISO: SERCOM4/PAD[3]
  { PORTB, 12, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_12 }, // MOSI: SERCOM4/PAD[0]
  { PORTB, 13, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_13 }, // SCK: SERCOM4/PAD[1]


S1buell

Testing:

when I put the code like this my SCL pin blinks (Expected)

  // 20..21 I2C pins (SDA/SCL) // These will change as will all the below pins
  // ----------------------
  { PORTA, 22, PIO_SERCOM, PIN_ATTR_PWM_G, No_ADC_Channel, TC4_CH0, TC4_CH0, EXTERNAL_INT_6 }, // SDA: SERCOM3/PAD[0]
  { PORTB,  4, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, //Added this line, Line 20
  { PORTA, 23, PIO_SERCOM, PIN_ATTR_PWM_G, No_ADC_Channel, TC4_CH1, TC4_CH1, EXTERNAL_INT_7 }, // SCL: SERCOM3/PAD[1]

When I put the code to this my A5 Blinks (Expected)

 // 14..20 - Analog pins changed 19 to 20
  // --------------------
  { PORTA,  2, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 },
  { PORTB,  8, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel2, TC4_CH0, TC4_CH0, EXTERNAL_INT_8 },
  { PORTB,  9, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel3, TC4_CH1, TC4_CH1, EXTERNAL_INT_9 },
  { PORTA,  4, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel4, TC0_CH0, TC0_CH0, EXTERNAL_INT_6 },
  { PORTA,  5, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel5, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 },
  { PORTB,  4, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, //Added this line, Line 20
  { PORTB,  2, PIO_ANALOG, (PIN_ATTR_ANALOG|PIN_ATTR_PWM_E), ADC_Channel14, TC6_CH0, TC6_CH0, EXTERNAL_INT_2 },

But when I place the line at exactly line 20 nothing happens


Its like its not accepting this pin...

Now This part of the board is custom. I'm using the template from SAMD51 Thing Plus. Its the same MCU but I'm trying to use all the pins. I'm guessing if I want to use these pins there is one or two other files I need to edit. I'm I correct?

pert

Where do I find this mapping "Since A6 is Arduino pin number 20 (14 + 6)"
Here:
Code: [Select]
#define PIN_A0               (14ul)
...
Code: [Select]
#define PIN_A6               (PIN_A0 + 6) //added
...
Code: [Select]
static const uint8_t A6  = PIN_A6; //added this line

MartinL

Hi S1buell,

Please find attached the "variant.h" and "variant.cpp" files for my custom SAMD51J20A board.

The "variant" files for my custom board more closely resemble the pin allocations of the Arduno Zero than Adafruit's boards.

In addition, I also added the __SAMD51J20A__ build flag to the "boards.txt" file. This allows the compiler to access the CMSIS pin definitions for the "J" variant:

Code: [Select]
adafruit_metro_m4.build.extra_flags=-D__SAMD51J20A__ -D__SAMD51__ {build.usb_flags} -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16

S1buell

@ pert

Thanks that helps a ton. I will have a look at this and get back to you.... Need a little time to sit down and look at this in detail. But I understand the connection now. Thanks for the help its been amazing. I will post the details if/when I get this working for others to view.

@martinL

Wow.... Bam there it is..... lol
Let me have a look at this. I`m really loving this SAMD51 project. I will have a look at what you have done and see how It can add some clarity to my issue.

Question did you uses all the pins on the MCU?


S1buell

Ok had a little time today...

Here`s what I have

Boards.txt has access the CMSIS pin definitions for the "J" variant:
samd51_thing_plus.build.extra_flags=-D__SAMD51J20A__ -D__SAMD51__ {build.usb_flags} -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16


Variant.h (mods)

// Number of pins defined in PinDescription array
#define PINS_COUNT           (37u) //added one, 36 to 37
#define NUM_DIGITAL_PINS     (20u)
#define NUM_ANALOG_INPUTS    (7u) //added 1, 6 to 7
#define NUM_ANALOG_OUTPUTS   (1u)
#define analogInputToDigitalPin(p)  ((p < 7u) ? (p) + 14u : -1)  //change 6u to 7u

* Analog pins
*/
#define PIN_A0               (14ul)
#define PIN_A1               (PIN_A0 + 1)
#define PIN_A2               (PIN_A0 + 2)
#define PIN_A3               (PIN_A0 + 3)
#define PIN_A4               (PIN_A0 + 4)
#define PIN_A5               (PIN_A0 + 5)
#define PIN_A6               (37ul) //added this line

Also tried
#define PIN_A6               (PIN_A6 + 23) //added this line 37

#define PIN_DAC0             (14ul)
#define PIN_DAC1             PIN_A1

static const uint8_t A0  = PIN_A0;
static const uint8_t A1  = PIN_A1;
static const uint8_t A2  = PIN_A2;
static const uint8_t A3  = PIN_A3;
static const uint8_t A4  = PIN_A4;
static const uint8_t A5  = PIN_A5;
static const uint8_t A6  = PIN_A6;  // Added this line

Variant.ccp

// 33..36 SPI for Flash (SCK, CS, MISO, MOSI)
{ PORTA, 9, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //SCK
{ PORTA, 10, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //CS
{ PORTA, 11, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //MISO
{ PORTA, 8, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //MOSI

// SAMD21J18A Pins...#####################  //Added these lines ######################3

// 37..40 - Analog pins
{ PORTB,  4, PIO_ANALOG, 0, ADC_Channel12, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, // ADC/AIN[12]
//  { PORTB,  5, PIO_ANALOG, 0, ADC_Channel13, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 }, // ADC/AIN[13]
//  { PORTB,  6, PIO_ANALOG, 0, ADC_Channel14, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6 }, // ADC/AIN[14]
// { PORTB,  7, PIO_ANALOG, 0, ADC_Channel15, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 }, // ADC/AIN[15]

Let me know if that looks right. I will test tonight.

BTW I`m just working on the PB4 pin for now.


S1buell

Well.... That didn't work as I planed the new changes did not give me access to A6 / PB04

hemmmm


S1buell

@MartinL

Are these Variant files correct they don`t seems to match. Also I found this in the variant.ccp line 199

 // SAMD21J18A Pins...

e.g

Variant.h
/*
 * Analog pins
 */
#define PIN_A0               (14ul)
#define PIN_A1               (PIN_A0 + 1)
#define PIN_A2               (PIN_A0 + 2)
#define PIN_A3               (PIN_A0 + 3)
#define PIN_A4               (PIN_A0 + 4)
#define PIN_A5               (PIN_A0 + 5)
#define PIN_A6               (PIN_A0 + 6)
#define PIN_A7               (PIN_A0 + 7)
#define PIN_A8               (PIN_A0 + 8)
#define PIN_A9               (PIN_A0 + 9)
#define PIN_DAC0             (14ul)
#define PIN_DAC1             PIN_A1

Variant.ccp
// 14..19 - Analog pins
  // --------------------
  { PORTA,  2, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 }, // ADC/AIN[0]
  { PORTB,  8, PIO_ANALOG, 0, ADC_Channel2, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_8 }, // ADC/AIN[2]
  { PORTB,  9, PIO_ANALOG, 0, ADC_Channel3, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_9 }, // ADC/AIN[3]
  { PORTA,  4, PIO_ANALOG, 0, ADC_Channel4, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, // ADC/AIN[4]
  { PORTA,  5, PIO_ANALOG, 0, ADC_Channel5, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 }, // ADC/AIN[5]
  { PORTB,  2, PIO_ANALOG, 0, ADC_Channel10, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 }, // ADC/AIN[10]

  // 20..21 I2C pins (SDA/SCL and also EDBG:SDA/SCL)
  // ----------------------
  { PORTA, 22, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6 }, // SDA: SERCOM3/PAD[0]
  { PORTA, 23, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 }, // SCL: SERCOM3/PAD[1]

westfw

I really like to fill out a spreadsheet like https://docs.google.com/spreadsheets/d/1hWHiM1Sk-gxcUmfgm5XQctqf9yaOnkmY66cwd_sRCiY/edit?usp=sharing
It gives me a good sense of what's there, what's connected, what's left over...
In combination with the ability to sort the spreadsheet by (chip pin number, port/pin number, arduino pin number, or any of the functions...  It can be very clarifying.)


Quote
// SAMD21J18A Pins...#####################  //Added these lines ######################3
Since the g_APinDescription array is just an array, exactly WHERE you added those lines is as important as what was in them...  Post the whole thing.


MartinL

Hi S1buell,

You're right, my apologies. The variant files that I provided aren't able to activate the analog input on PB04. This is because as the comment suggests, they've been cut 'n' pasted from the SAMD21J18A. This works for digital IO on both the SAMD21/SAMD51, but not for analog inputs on the SAMD51.

There are two issues. The first is that the "variant.h" file needs to be corrected to address the right analog pin:
 
Code: [Select]
/*
 * Analog pins
 */
#define PIN_A0               (14ul)
#define PIN_A1               (PIN_A0 + 1)
#define PIN_A2               (PIN_A0 + 2)
#define PIN_A3               (PIN_A0 + 3)
#define PIN_A4               (PIN_A0 + 4)
#define PIN_A5               (PIN_A0 + 5)
#define PIN_A6               (44ul)
#define PIN_A7               (PIN_A6 + 1)
#define PIN_A8               (PIN_A6 + 2)
#define PIN_A9               (PIN_A6 + 3)
#define PIN_DAC0             (14ul)
#define PIN_DAC1             PIN_A1

The second is that PB04 uses the SAMD51's ADC1 rather than ADC0, this requires selection of the alternative analog pin attribute: PIN_ATTR_ANALOG_ALT.

Just replace the pin entries for 44 to 47 in the "variant.cpp" file with:

Code: [Select]
// 44..47 - Analog pins
{ PORTB,  4, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, // ADC1/AIN[6]
{ PORTB,  5, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel7, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 }, // ADC1/AIN[7]
{ PORTB,  6, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel8, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6 }, // ADC1/AIN[8]
{ PORTB,  7, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel9, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 }, // ADC1/AIN[9]

It should then be possible to activate the analog input on PB04 with:

Code: [Select]
int result = analogRead(A6);

S1buell

Ok here are my changes I will test tonight.

@westfw

I attached the complete files to review. I will look at the document you sent tonight... I was thinking last night...... Man I need something to help organize these pins.... I`m guessing this sheet is exactly what I need. Thanks again!  

@martin

Ok top part of variant.h is as follows:

Code: [Select]
/*----------------------------------------------------------------------------
*        Pins
*----------------------------------------------------------------------------*/

// Number of pins defined in PinDescription array
// Modified only for PB4 test
#define PINS_COUNT           (37u) //added one, 36 to 37
#define NUM_DIGITAL_PINS     (20u)
#define NUM_ANALOG_INPUTS    (7u) //added 1, 6 to 7
#define NUM_ANALOG_OUTPUTS   (1u)
#define analogInputToDigitalPin(p)  ((p < 7u) ? (p) + 14u : -1)  //change 6u to 7u

#define digitalPinToPort(P)        ( &(PORT->Group[g_APinDescription[P].ulPort]) )
#define digitalPinToBitMask(P)     ( 1 << g_APinDescription[P].ulPin )
//#define analogInPinToBit(P)        ( )
#define portOutputRegister(port)   ( &(port->OUT.reg) )
#define portInputRegister(port)    ( &(port->IN.reg) )
#define portModeRegister(port)     ( &(port->DIR.reg) )
#define digitalPinHasPWM(P)        ( g_APinDescription[P].ulPWMChannel != NOT_ON_PWM || g_APinDescription[P].ulTCChannel != NOT_ON_TIMER )

/*
* digitalPinToTimer(..) is AVR-specific and is not defined for SAMD
* architecture. If you need to check if a pin supports PWM you must
* use digitalPinHasPWM(..).
*
* https://github.com/arduino/Arduino/issues/1833
*/
// #define digitalPinToTimer(P)

// LEDs
#define PIN_LED_13           (13u)
#define PIN_LED_RXL          (25u)
#define PIN_LED_TXL          (26u)
#define PIN_LED              PIN_LED_13
#define PIN_LED2             PIN_LED_RXL
#define PIN_LED3             PIN_LED_TXL
#define LED_BUILTIN          PIN_LED_13

/*
* Analog pins
*/
#define PIN_A0               (14ul)
#define PIN_A1               (PIN_A0 + 1)
#define PIN_A2               (PIN_A0 + 2)
#define PIN_A3               (PIN_A0 + 3)
#define PIN_A4               (PIN_A0 + 4)
#define PIN_A5               (PIN_A0 + 5)
#define PIN_A6               (37ul) //added this line A5 is pin 37
//#define PIN_A7               (PIN_A6 + 1)
//#define PIN_A8               (PIN_A6 + 2)
//#define PIN_A9               (PIN_A6 + 3)


#define PIN_DAC0             (14ul)
#define PIN_DAC1             PIN_A1

static const uint8_t A0  = PIN_A0;
static const uint8_t A1  = PIN_A1;
static const uint8_t A2  = PIN_A2;
static const uint8_t A3  = PIN_A3;
static const uint8_t A4  = PIN_A4;
static const uint8_t A5  = PIN_A5;
static const uint8_t A6  = PIN_A6;  // Added this line
//static const uint8_t A7  = PIN_A6;  // Added this line
//static const uint8_t A8  = PIN_A6;  // Added this line
//static const uint8_t A9  = PIN_A6;  // Added this line

static const uint8_t DAC0 = PIN_DAC0;
static const uint8_t DAC1 = PIN_DAC1;

#define ADC_RESOLUTION 12


Code: [Select]
Variant.ccp (feom line 31 on...

// ----------------------
// 31..32 - Alternate use of A0/A4 (DAC output)
{ PORTA,  2, PIO_ANALOG, PIN_ATTR_ANALOG, DAC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // DAC/VOUT0
{ PORTA,  5, PIO_ANALOG, PIN_ATTR_ANALOG, DAC_Channel1, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // DAC/VOUT1

// ----------------------
// 33..36 SPI for Flash (SCK, CS, MISO, MOSI)
{ PORTA, 9, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //SCK
{ PORTA, 10, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //CS
{ PORTA, 11, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //MISO
{ PORTA, 8, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, //MOSI

// SAMD21J18A Pins...#####################  //Added these lines ######################3


// 37..40 - Analog pins (Test PB4 first, Then the rest)
{ PORTB,  4, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, // ADC1/AIN[6]
//{ PORTB,  5, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel7, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 }, // ADC1/AIN[7]
//{ PORTB,  6, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel8, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6 }, // ADC1/AIN[8]
//{ PORTB,  7, PIO_ANALOG, PIN_ATTR_ANALOG_ALT, ADC_Channel9, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 }, // ADC1/AIN[9]









MartinL

Hopefully this should work. Using the PIN_ATTR_ANALOG_ALT pin attribute should get the analogRead() funtion to switch over to ADC1, which is what you require for port pin PB04:

Inside the analogRead() funtion:

Code: [Select]
#if defined(__SAMD51__)
  Adc *adc;
  if(g_APinDescription[pin].ulPinAttribute & PIN_ATTR_ANALOG) adc = ADC0;
  else if(g_APinDescription[pin].ulPinAttribute & PIN_ATTR_ANALOG_ALT) adc = ADC1;
  else return 0;

S1buell

Ok, tried the first changes and nothing. I will look at what you send me.

Go Up