GPIO pin low after bitwise operation

Hello,

On the CPLD which I am using I have a chip attached, via an I2C connection. This chip I control via my software driver. I now see something strange thing. When I set the clock-line, then the data-line goes low in case I do this with the following line of C-code:

port |= MASK_SCL;

But, when I apply the following C-code everyting goes fine:

mirror |= MASK_SCL; port = mirror;

Anyone got an idea? Perhaps it has something to do with the electronics? The current going down or something like that?

Kind regards, Harayasu

Reply to
Harayasu
Loading thread data ...

Perhaps the port is write-only. Or the macro used to address the port can't deal with read-modify-write.

Steve

formatting link

Reply to
Steve at fivetrees

On 4 Aug 2006 14:28:20 -0700, "Harayasu" wrote in comp.arch.embedded:

That depends on how the GPIO is programmed in your CPLD. When you read back the address, do you get the bits you wrote, or are they write only?

--
Jack Klein
Home: http://JK-Technology.Com
 Click to see the full signature
Reply to
Jack Klein

Your problem sounds like your CPLD samples the actual pin value when you read the port, instead of returning the value in the port driving register. If this is the case, your 2nd code snippet is a very straight-forward way to work around the problem. Remember that even though you write one line of C code: "port |= MASK_SCL", you are really instructing the hardware to two three things: 1) read the current port value 2) apply a bitwise OR to the value read, and 3) to write the value back to the port.

If during step 1, the device returns the actual state of the pins, rather than the value in the port register, anything external to the device which is driving the pin to a logical low state will cause the bit to read as a 0 instead of the 1 that you had in the register before. The bit survives the OR done in step #2, and then is written back out as a 0 in step #3. Check your datasheet and see if this is the case.

Reply to
Travis Hayes

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.