I'm trying to have some GPIO pins on my SoC board available by default at boot. I've run across the gpio-hog property in the device tree documentation here, and I have my 'hogged' pin visible in userspace. How can I see the value of that pin? It's configured as an input.
Related
I have been studying about SPI and would like to clarify few more things:
1.
I am trying to understand about CPOL and CPHA in particular:
I have a device (MCP41 that I want to write SPI drivers for). The datasheet can be found here:
https://ww1.microchip.com/downloads/en/devicedoc/11195c.pdf
According to the timing diagram:
It mentions that Data is always latched in on the rising edge of the SCK. Is that supposed to give me any hints about CPHA?
It also mentions that the Data is always clocked out of the SO pin after the falling edge of SCK. Since it mentions falling edge of the SCK, I understand that the CPHA for this device should be set to 1, is that correct?
2 What if I have 2 SPI devices connected to the same SPI bus. One device requires CPOL = 0, CPHA = 0 and the other device requires CPOL = 0 and CPHA = 1. Does that mean it will not be possible to communicate with both devices via single SPI bus?
The timing diagram shows that this device requires SPI mode 0: CPOL=0 CPHA=0.
The way to read the diagram is that the clock idles low, so CPOL=0. The data is sampled (called "latched" above) on the rising edge. This is the first edge when starting low so CPHA=0 (the rising edge would be the second edge if starting high).
The comment about output data on the falling edge simply means that the device outputs the next data starting on the second edge of the preceding pulse, this way it is ready in time for the first edge of the next clock pulse.
For your second question, yes you can mix different clock modes (polarity, phase and speed) on the same bus, as long as you make all the changes when no device is selected, ie: when all chip-selects are high. You may want to even change the mode of the chip select pins momentarily to GPIO while you deconfigure and reconfigure the SPI peripheral (I'm never sure what alt-function pins will output while you are messing with the registers of a disabled peripheral).
Is it possible to measure 3 specific resistor values by using GPIO / Without using a full ADC setup?
I have an alarm sensor that I want to hook up to my GPIO. This sensor has 3 specific resistors value, based on it's state:
1) Normal - 4k7
2) Alarm - 9k3
3) Tamper - infinite.
Due to long lines, I would prefer 12V power on one side.
I would like to be able to detect these states by 2 normal GPIO input pins.
Is that even possible? What would be the schematic needed for this?
Or is the only solution to use (external) ADC's?
I am thinking about a voltage diver with resistors and a 1N4148 diode to clip it to 3v3. But so far my results are unfruitfull.
Thanks.
The problem here is you have three levels to measure. If we had two we could use a simple resistor divider setup to make (say) the 4k7 and 9k3 outputs on the sensor to logic 0 (<=0.8V) or logic 1 (>=1.3V) on a single GPIO pin. We could do this on two GPIO pins if we had two "independent samples" of the sensor output rather than one.
Given the above it is possible to design some simple logic network to do the comparisons but as the other comment mentions you're off into the realms of electronics.
ADC is the simplest way to go if you want to stay in the software domain. The are other SBC devices e.g. ESP8266 which have onboard ADC functionality and built-in Wifi https://esp8266-projects.org/2015/03/internal-adc-esp8266/ or you can hook up an add-on ADC to the Rpi for example https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters
Good luck
I'm confused regarding how much current 5LP GPIO pins can drive; any help is appreciated.
Here's where I get confused:
The CY8CKIT-059's "User LED BLUE" is an LTST-C170TBKT from Lite-On
Inc.
This LED has a DC Forward Current of 20 mA, according to its
data sheet.
On the CY8CKIT-059, this LED is driven by a single pin
P2_1 (via a 820 ohm resister), according to the CY8CKIT-059
schematics.
Cypress AN72382, ยง 2.4 states "In general, [PSOC 5LP]
GPIO pins can source 4 mA."
My confusion: If the PSOC 5LP GPIO pins can only source 4 mA (unless ganged), then how can pin P2_1 drive enough current to light "User LED BLUE" if that LED has a DC Forward Current of 20 mA?
What am I missing here?
I'm sure it is something really obvious.
Thanks in advance,
-Chris
The key distinction is source vs. sink, the pins can source less current than they can sink. Note: The concepts should be considered in terms of conventional current flow (positive to negative.)
Sourcing current involves connecting the I/O pin to VCCIOx (positive). Sinking current involves connecting the I/O pin to GROUND.
When driving a LED we will typically connect the LED to a positive voltage source, then to the I/O pin through a resistor. When we want the LED to turn on, the pin must sink current to ground. The pins can control more current this way.
(Image from CircuitsToday.com)
I'm having a Chinese development board of STM32F103RCT6 STM32_Mini_Pro where a winbond SPI flash is attached with SPI3. The Chip Select is attached with PA15 pin.
While configuring SPI in STM32 cubeMX, I assign Chip Select i.e. PA15 as GPIO output for software NSS.
But while assigning it i get an error like this
This is my assignment in Cube MX
What is the reason for this problem and how to rectify it?
Thank you
There is no problem. Cube shows you that you can not assign slave select signal to PA15 (yes, it's rigth, you already mapped this pin as GPIO).
Hardware slave select it STM32 micros has the meaning only if you use MCU as slave device.
My Zynq board has SPI, I2C but does not have kernel level GPIO (The GPIO on the MIO is sent to a bunch of other things) so I can't get it from the headers. Believe me when I say this.
I need some kernel level GPIO so I can drive a touch screen interface. I need to map some GPIO to the stmpe610 touch screen driver (Device Tree compatible = "st,stmpe610"). This is all well and good. So what I want to do is somehow map the I2C to GPIO (which will be connected to the display), and pipe the driver to interface through I2C. This way I can access the GPIO pins of my i2c expander from kernel space.
I looked at the i2c-gpio driver, but it does the opposite of what I want (http://lwn.net/Articles/230571/). It takes GPIO and makes it I2C by bit-banging.
I have an i2c expander mini-board that will take I2C and spit out GPIO. So if I have a gpio-i2C that would be great.
Maybe I have wandered too afar and off the beaten path. Does the stmpe610 have an i2c driver? This would also alleviate my issue.
<<
If I have understood you correctly, you have a GPIO expansion board that you can connect to your Zync main board.
If the above assumption is correct, what you have to do is find the correct driver for your GPIO extension board. What model do you have ? What chip is there on it ? Maybe there is already a driver for it in the kernel. If so, you then just have to declare it under your I2C base controller node in your device tree so that its GPIOs can then be referenced in your device tree for your stmpe610 touchscreen node.
If the chip does not have a driver yet, you then will have to write a GPIO driver for the chip. One good example to start with is the GPIO driver for the MAX 7300, that is connected via I2C as well. Have a look at gpio-max7300.c and gpio-max730x.c