I need some help to understand why my PINs aren't getting set to HIGH and LOW properly. As the title says I'm using ATSAMD10D13AS. The following function is supposed to set the PINs to LOW, then wait for 10 seconds and the two commented lines should reset the PINS to be inputs and finally the second for loop is supposed to turn the pins HIGH and wait for 10 seconds before once again setting the pins to input mode (REG_PORT_DIR0 &= ~(PORT_PA05 | PORT_PA06 | PORT_PA07 | PORT_PA08 | PORT_PA09 | PORT_PA14 | PORT_PA15);). However once I set the pins to inputs using either REG_PORT_DIR0 or REG_PORT_DIRCLR0, they never go to HIGH state in the second for loop. Register descriptions in the datasheet
struct pinSettings pinsettings = {
.number = {0x7D, 0x5, 0x5B, 0x4F, 0x27, 0x6E, 0x7E, 0x45, 0x7F, 0x6F},
.segmentPinOrder = {5, 6, 7, 8, 9, 14, 15},
.clear = 0x00
};
bool displayToggleNumber(uint8_t numberToDisplay) {
PWMbegin();
numberToDisplay = pinsettings.number[numberToDisplay];
for (uint8_t i = 0; i < 7; ++i) {
REG_PORT_DIR0 |= (1 << pinsettings.segmentPinOrder[i]);
REG_PORT_DIRSET0 |= (1 << pinsettings.segmentPinOrder[i]);
REG_PORT_OUTCLR0 |= (1 << pinsettings.segmentPinOrder[i]);
}
setOnPercent(45);
DelayMs(10000);
//REG_PORT_DIR0 &= ~(PORT_PA05 | PORT_PA06 | PORT_PA07 | PORT_PA08 | PORT_PA09 | PORT_PA14 | PORT_PA15);
//REG_PORT_DIRCLR0 |= (PORT_PA05 | PORT_PA06 | PORT_PA07 | PORT_PA08 | PORT_PA09 | PORT_PA14 | PORT_PA15);
for (uint8_t i = 0; i < 7; ++i) {
if ((numberToDisplay >> i) & 1) {
// 1 << 5 == PORT_PA05 set PIN 5 as output
REG_PORT_DIR0 |= (1 << pinsettings.segmentPinOrder[i]);
REG_PORT_DIRSET0 |= (1 << pinsettings.segmentPinOrder[i]);
REG_PORT_OUTSET0 |= (1 << pinsettings.segmentPinOrder[i]);
}
}
setOnPercent(55);
DelayMs(10000);
// set all pins to inputs until the new number is received
REG_PORT_DIR0 &= ~(PORT_PA05 | PORT_PA06 | PORT_PA07 | PORT_PA08 | PORT_PA09 |
PORT_PA14 | PORT_PA15);
return true;
}