樹莓派 HATs ︰ 初探之原點

既知 ID EEPROM 接在 I2C-0 BUS 之上,且讓我們以樹莓派 3B 機版為例 ,關閉所有 I2C BUS ,作為 HATs 初探的原點。

pi@raspberrypi:~ i2cdetect -l pi@raspberrypi:~ 
pi@raspberrypi:~ gpio readall  +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+  | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |  +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+  |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |  |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |  |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |  |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 0 | IN   | TxD     | 15  | 14  |  |     |     |      0v |      |   |  9 || 10 | 1 | IN   | RxD     | 16  | 15  |  |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |  |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |  |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |  |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |  |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |  |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |  |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |  |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |  |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |  |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |  |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |  |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |  |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |  |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |  |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |  +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+  | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |  +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+ pi@raspberrypi:~ 

 

使用 dtparam 指令,動態啟動 I2C-0 匯流排,

pi@raspberrypi:~ sudo dtparam i2c_vc=on  pi@raspberrypi:~ i2cdetect -l
i2c-0	i2c       	3f205000.i2c                    	I2C adapter
pi@raspberrypi:~ cd /sys/class/i2c-adapter/ pi@raspberrypi:/sys/class/i2c-adapter ls
i2c-0
pi@raspberrypi:/sys/class/i2c-adapter i2cdetect -y 0      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f 00:          -- -- -- -- -- -- -- -- -- -- -- -- --  10: -- -- -- -- -- -- -- -- -- -- -- -- 1c -- -- --  20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  40: -- -- -- 43 -- -- -- -- -- -- -- -- -- -- -- --  50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  70: -- -- -- -- -- -- -- --                          pi@raspberrypi:/sys/class/i2c-adapter

 

查看系統訊息,

pi@raspberrypi:/sys/class/i2c-adapter dmesg | tail [   11.912918] Bluetooth: HCI UART protocol H4 registered [   11.912923] Bluetooth: HCI UART protocol Three-wire (H5) registered [   11.913033] Bluetooth: HCI UART protocol BCM registered [   12.078294] Bluetooth: BNEP (Ethernet Emulation) ver 1.3 [   12.078319] Bluetooth: BNEP filters: protocol multicast [   12.078344] Bluetooth: BNEP socket layer initialized [   28.853741] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null) [   98.319535] bcm2708_i2c 3f205000.i2c: BSC0 Controller at 0x3f205000 (irq 83) (baudrate 100000) [  161.917886] i2c i2c-0: transfer timed out [  162.927891] i2c i2c-0: transfer timed out pi@raspberrypi:/sys/class/i2c-adapter

 

發現竟然已有兩個裝置在上頭。

據聞其一用於樹莓派鏡頭的控制,

RasPiCam Hot plug

by liuxin_john » Wed Jun 05, 2013 11:24 am

When raspberry pi bootup with piCamera attach to it, I can use “raspistill” to take a picture.

I have 2 questions about this:
1. If raspberry pi bootup without piCamera attach, then I plug piCamera to raspberry pi. In this case, I can not use “raspistill” to take a picture
2. If raspberry pi bootup with piCamera attach to it, After use “raspistill” to take a picture, I plug out piCamera and then plug in a new piCamera to raspberry pi, I also can not use “raspistill” to take a picture.

Any body know the reason and how to solve it. :roll:

……

by liuxin_john » Wed Jun 05, 2013 2:34 pm

Hi Jamesh

I notice that the GPU part of the Raspi is closed source.
And seems the RasPiCam is controlled by I2C, does the I2C driver for RasPiCam is also closed source or I can see it from github?
Thanks a lot!

……

by jamesh » Wed Jun 05, 2013 2:50 pm

liuxin_john wrote:Hi Jamesh

I notice that the GPU part of the Raspi is closed source.
And seems the RasPiCam is controlled by I2C, does the I2C driver for RasPiCam is also closed source or I can see it from github?
Thanks a lot!

All the communication from the Raspi to the camera and from camera to Raspi is done from the GPU and is therefore closed source.

 

由於是 closed source ,故而欲作樹莓派 CSI 相容之鏡頭,不易也。

另一提供樹莓派 7″ 顯示器的觸控螢幕

by JimmyN » Fri Sep 11, 2015 7:52 pm

 

I followed this https://www.raspberrypi.org/blog/the-ea … i-display/ to get the display up and running. I used the GPIO option to power the RPi, connecting the 5V & GND on the display’s I2C connector over to pins #4 and #6 on the RPI. But the blog only shows the power pins in use, with no connection to SDA, SCL.

I had assumed that the I2C connections on the display interface were for the touch screen, so I went ahead and connected them up at first. But I have found that touch works whether they are connected or not. I currently have SDA and SCL unplugged and everything seems to work the same.

So should they be connected, or are they for some feature I haven’t yet discovered?

……

by Rob73 » Sat Mar 19, 2016 4:05 pm

Using other-i2c-devices with the Official 7″ Touchscreen

If my understanding is correct, then the Touch-Input of the Official 7″ Touchscreen uses i2c to communicate touches to the Raspberry Pi.

In the RasPi-2B and RasPi-3B (at least), the Official 7″ Touchscreen seems to use i2c-0, which is passed through the ribbon “Display Connector”. Thus is appears that i2c-1 on these versions of the RasPi is still available on the GPIO pins for other use: I have successfully connected a DS3231-RTC to the GPIO_i2c-1 on my RasPi-2B and RasPi-3B, and the touch-functions of the Touchscreen continue to work fine.

[I would postulate that on the original RasPi-A and RasPi-B that the Touchscreen still uses i2c-0, but on these original RasPi’s this is the same i2c-0 which is on Pins #3 & #5 on the GPIO (to which on these original models you have to use jumper-wires on the GPIO SDA & SCL to connect to the Touchscreen). Which means that you can’t use this GPIO i2c for anything else on these original RasPi-A & -B, UNLESS (perhaps) you disable the touch-functions of the Touchscreen (eg. by putting “disable_touchscreen=1” in config.txt, and also disconnecting the i2c-jumper-cables) – which MIGHT allow you to then use the GPIO i2c for something else on these original RasPi’s??]

If anyone could confirm the above is correct, it would be appreciated!?!

Update (23Mar): Many thanks for concise reply! :-)

……

by 6by9 » Sat Mar 19, 2016 5:37 pm

Yes, your understanding is correct.

A+, B+, 2, and 3 all use i2c0 for configuring the display and touchscreen. I2c1 is still available for other uses.

A and B need to use the other i2c bus for the display via additional wires – whether that is 0 or 1 I think varies between revisions.

 

想來亦是閉源軟體的了。

雖曉系統裡並無 ID EEPROM ,何妨趁機驗證 eepflash 讀取錯誤時之狀況乎!!??

pi@raspberrypi:~/hats/eepromutils sudo ./eepflash.sh -h eepflash: Writes or reads .eep binary image to/from HAT EEPROM on a Raspberry Pi  ./eepflash.sh 	-h --help: display this help message 	-r --read: read .eep from the eeprom 	-w --write: write .eep to the eeprom 	-f=file_name --file=file_name: binary .eep file to read to/from 	-t=eeprom_type --type=eeprom_type: eeprom type to use 		We support the following eeprom types: 		-24c32 		-24c64 		-24c128 		-24c256 		-24c512 		-24c1024  pi@raspberrypi:~/hats/eepromutils
pi@raspberrypi:~/hats/eepromutils sudo ./eepflash.sh -r -f=test.eep -t=24c32 This will attempt to talk to an eeprom at i2c address 0x50. Make sure there is an eeprom at this address. This script comes with ABSOLUTELY no warranty. Continue only if you know what you are doing. Do you wish to continue? (yes/no): yes Reading... dd: 讀取 '/sys/class/i2c-adapter/i2c-3/3-0050/eeprom' 時發生錯誤: 連線超過時間 0+0 records in 0+0 records out 0 bytes (0 B) copied, 0.0416229 s, 0.0 kB/s Error doing I/O operation.  pi@raspberrypi:~/hats/eepromutils cd /sys/class/i2c-adapter/
pi@raspberrypi:/sys/class/i2c-adapter ls i2c-0  i2c-3 pi@raspberrypi:/sys/class/i2c-adapter i2cdetect -y 3
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

pi@raspberrypi:/sys/class/i2c-adapter cd i2c-3/ pi@raspberrypi:/sys/class/i2c-adapter/i2c-3 ls
3-0050         device   name        of_node  subsystem
delete_device  i2c-dev  new_device  power    uevent

pi@raspberrypi:/sys/class/i2c-adapter/i2c-3 cd 3-0050/ pi@raspberrypi:/sys/class/i2c-adapter/i2c-3/3-0050 ls
driver  eeprom  modalias  name  power  subsystem  uevent

pi@raspberrypi:/sys/class/i2c-adapter/i2c-3/3-0050 cat name 24c32  pi@raspberrypi:/sys/class/i2c-adapter/i2c-3/3-0050 sudo cat eeprom 
cat: eeprom: 連線超過時間
pi@raspberrypi:/sys/class/i2c-adapter/i2c-3/3-0050 </pre> <pre class="lang:default decode:true">pi@raspberrypi:~ gpio readall
 +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 0 | IN   | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | IN   | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
pi@raspberrypi:~ $