I suspected that something as simple as this had to have a simple (yet improbable) explanation and it did.
Turns out both regulators were busted. I don't remember where I got them from, they looked unused, but who knows. I tried with the same model but bought at a different time, maybe from another supplier, and works as expected.
The testing setup was correct and filter capacitors aren't really needed (at least for testing purposes), but I'll use them anyway as recommended. Thank you all for your input.
When examining a single bit in a byte (or register) using & it's important to remember that the result of the & will be a masked value, not the value of the bit you're interested in.
For example, if you have the value 0b10110101 in a register and you want to examine bit 2, you could mask it out with 0b00000100:
0b10110101
0b00000100 &
==========
0b00000100 = 4
So the result is, in decimal, 4. In your if
statement you are comparing the results of the & operation with 1. That can only ever be true if you happen to be examining bit 0 in your register.
If you change your comparison either so it's comparing the masked value to the value of the mask then it can become true for the value you're actually examining.
Better still, drop the comparison altogether:
if (GPIOX_DATA & 0xXX) // IF THE PORTS' DATA REGISTER, AT PIN, IS HIGH,
GPIOX_DATA |= 0xXX; // SET THIS PORTS' DATA REGISTER, AT PIN, TO HIGH
In an if
comparison you're only interested in a true
or false
state. In C a false state is defined as 0, and a true state is defined as any other value but 0. So say the equation GPIOX_DATA & 0xXX
results in 4, that is a true value, since it's not 0.
Best Answer
Consider Port A (just another name for your port) and write a code to Toggle A.0 after 3 seconds while the rest of the pins of this port and other ports are set at LOW. Use multimeter between A.0 and GND and If you see voltage fluctuations and not a constant zero voltage , meaning its fine. Repeat this for the rest of the remaining pins.Before performing this make sure that power pins and oscillator pins are not short circuited. If there is some availability of an internal RC oscillator, use that instead of external
It's obviously time consuming since this is what I came up at my own and probably this forum will answer you some other great methods.