EmbeddedRelated.com
Forums
Memfault Beyond the Launch

GPIO pin low after bitwise operation

Started by Harayasu August 4, 2006
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

"Harayasu" <h_onagi@hotmail.com> wrote in message 
news:1154726900.283830.162010@i3g2000cwc.googlegroups.com...
> 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?
Perhaps the port is write-only. Or the macro used to address the port can't deal with read-modify-write. Steve http://www.fivetrees.com
On 4 Aug 2006 14:28:20 -0700, "Harayasu" <h_onagi@hotmail.com> wrote
in comp.arch.embedded:

> 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
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 FAQs for comp.lang.c http://c-faq.com/ comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
"Harayasu" <h_onagi@hotmail.com> wrote in message
news:1154726900.283830.162010@i3g2000cwc.googlegroups.com...
> 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?
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.

Memfault Beyond the Launch