embeded2015. 9. 8. 11:04

그냥 둘러보는 중?

일단 느낌은.. AVR/8051 보다 좀 더 저가의 주변기기 특화형 컨트롤러?

다량의 ADC와 더 적은 메모리 / 플래시

서로 일장일단이 있어 보이는데..


[링크 : http://ww1.microchip.com/downloads/en/DeviceDoc/39582C.pdf]


컴파일러로는 CCS compiler 라는게 있는 듯

[링크 : http://www.ccsinfo.com/]

    [링크 : https://www.ccsinfo.com/downloads/ccs_c_manual.pdf]

'embeded' 카테고리의 다른 글

링커 스크립트 문법(ld syntax)  (0) 2015.12.17
시리얼 저항 / 직렬 저항 / 댐핑 저항  (0) 2015.12.17
9$ computer C.H.I.P?  (0) 2015.05.27
PowerQUICC  (0) 2015.04.02
S29AL016J 플래시 메모리 BYTE/WORD MODE  (0) 2014.12.23
Posted by 구차니
embeded/raspberry pi2015. 9. 7. 16:43

흐음.. 한번 써봐야지


int waitForInterrupt (int pin, int timeOut) ;

gpio edge 0 falling


int wiringPiISR (int pin, int edgeType,  void (*function)(void)) ;

INT_EDGE_FALLING

INT_EDGE_RISING

INT_EDGE_BOTH

INT_EDGE_SETUP


gpio edge <pin> rising/falling/both/none

This enables the given pin for edge interrupt triggering on the rising, falling or both edges. (Or none which disables it)



       edge   This exports a GPIO pin  in  the  /sys/class/gpio  directory,  set  the

              direction  to  input and set the edge interrupt method to none, rising,

              falling or both.  Use like the  export  command  above  and  note  that

              BCM_GPIO pin number is used not not wiringPi pin numbering.


              Like the export commands above, ownership is set to that of the calling

              user, allowing subsequent access from user programs  without  requiring

              root/sudo. 


[링크 : http://wiringpi.com/reference/priority-interrupts-and-threads/]

[링크 : https://projects.drogon.net/raspberry-pi/wiringpi/functions/]

Posted by 구차니
embeded/raspberry pi2015. 9. 4. 18:44

pigpio 라는 다른 라이브러리가 존재한다.

[링크 : http://abyz.co.uk/rpi/pigpio/examples.html]


라즈베리 B 인거 같은데..

출력은 22Mhz 까지(단순하게 on/off만) 가능

[링크 : http://codeandlife.com/2012/07/03/benchmarking-raspberry-pi-gpio-speed/]


아무튼..

TSL235R 라는 녀석이 결과물이 주파수로 나와서

그걸 이용하는 예제

#!/usr/bin/python

import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)

GPIO.setup(25, GPIO.IN)


impuls_count = 0

# Do next lines for i.e. 1000ms:

GPIO.wait_for_edge(25, GPIO.FALLING)

impuls_count = impuls_count + 1


[링크 : http://stackoverflow.com/..../how-to-get-the-frequency-of-a-square-wave-in-a-python-script] 





Posted by 구차니
embeded/raspberry pi2015. 9. 3. 09:45

dht 관련 dtoverlay가 존재하는게 생각이 나서 삽질..

Name:   dht11

Info:   Overlay for the DHT11/DHT21/DHT22 humidity/temperature sensors

        Also sometimes found with the part number(s) AM230x.

Load:   dtoverlay=dht11,<param>=<val>

Params: gpiopin                  GPIO connected to the sensor's DATA output.

                                 (default 4)


[링크 : https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README] 


오홍 존재는 하네?(라즈비안)

$ sudo find / -name dht11.ko

/lib/modules/4.1.6+/kernel/drivers/iio/humidity/dht11.ko

/lib/modules/4.1.6-v7+/kernel/drivers/iio/humidity/dht11.ko


$ sudo modprobe dht11

$ lsmod | grep dht11

dht11                   3531  0

industrialio           35498  1 dht11


$ modinfo dht11

filename:       /lib/modules/4.1.6-v7+/kernel/drivers/iio/humidity/dht11.ko

license:        GPL v2

description:    DHT11 humidity/temperature sensor driver

author:         Harald Geyer <harald@ccbib.org>

srcversion:     136C0D2A25E76F8042B460C

alias:          of:N*T*Cdht11*

depends:        industrialio

intree:         Y

vermagic:       4.1.6-v7+ SMP preempt mod_unload modversions ARMv7 


/boot/overlays 에 파일이 존재하지 않아도 커널에 모듈로 내장되어 있는지 리부팅후 lsmod로 확인이 가능하다.

$ sudo vi /boot/config.txt

dtoverlay=dht11


/sys/devices/platform $ ls -al

합계 0

drwxr-xr-x 17 root root    0  9월  3 09:40 .

drwxr-xr-x  9 root root    0  9월  3 09:40 ..

drwxr-xr-x  2 root root    0  9월  3 09:44 alarmtimer

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD0.0

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD1.1

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD2.2

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD3.3

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD4.4

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD5.5

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD6.6

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD7.7

drwxr-xr-x  8 root root    0  9월  3 09:44 clocks

drwxr-xr-x  3 root root    0  9월  3 09:42 dht11@0

drwxr-xr-x  2 root root    0  9월  3 09:40 regulatory.0

drwxr-xr-x  2 root root    0  9월  3 09:44 serial8250

drwxr-xr-x 17 root root    0  9월  3 09:40 soc

drwxr-xr-x  2 root root    0  9월  3 09:44 timer

-rw-r--r--  1 root root 4096  9월  3 09:40 uevent


어짜피 이녀석은.. 위의 녀석의 심볼릭 링크

/sys/bus/iio/devices/iio:device0 $ ls -al

합계 0

drwxr-xr-x 2 root root    0  9월  3 09:42 .

drwxr-xr-x 3 root root    0  9월  3 09:42 ..

-r--r--r-- 1 root root 4096  9월  3 09:42 dev

-rw-r--r-- 1 root root 4096  9월  3 09:42 in_humidityrelative_input

-rw-r--r-- 1 root root 4096  9월  3 09:42 in_temp_input

-r--r--r-- 1 root root 4096  9월  3 09:42 name

lrwxrwxrwx 1 root root    0  9월  3 09:42 of_node -> ../../../../firmware/devicetree/base/dht11@0

lrwxrwxrwx 1 root root    0  9월  3 09:42 subsystem -> ../../../../bus/iio

-rw-r--r-- 1 root root 4096  9월  3 09:42 uevent



집에가서 센서 달고 해봐야지..


lm-sensor에서 dht11을 iio를 통해 값을 불러 올 수 있도록 수정 된 듯?

[링크 : http://lists.lm-sensors.org/pipermail/lm-sensors/2013-July/039283.html]



GPIO4 라고 되어있는데.. 그냥 핀번호 상으로 4번에 하니 먼가 되긴한다..

$ gpio readall

 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+

 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |

 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+

 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |

 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5V      |     |     |

 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |

 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |

 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | 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 |  OUT | 1 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |

 |     |     |    3.3v |      |   | 17 || 18 | 1 | OUT  | GPIO. 5 | 5   | 24  |

 |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |

 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 1 | OUT  | GPIO. 6 | 6   | 25  |

 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |

 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | 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 2---+---+------+---------+-----+-----+ 


/sys/bus/iio/devices/iio:device0 $ sudo cat in_*

65000

24000


/sys/bus/iio/devices/iio:device0 $ sudo cat in*
95000
19000

/sys/bus/iio/devices/iio:device0 $ sudo cat in_*
cat: in_humidityrelative_input: 입력/출력 오류
cat: in_temp_input: 연결 시간 초과

$ dmesg
[   93.266278] iio iio:device0: Only 0 signal edges detected
[   94.390030] dht11: WARNING: decoding ambiguous
[   95.416292] iio iio:device0: Only 0 signal edges detected
[  105.476356] iio iio:device0: Only 0 signal edges detected
[  113.646349] iio iio:device0: Only 0 signal edges detected
[  165.000461] dht11: WARNING: decoding ambiguous
[  199.120659] dht11: WARNING: decoding ambiguous
[  201.230684] dht11: WARNING: decoding ambiguous
[  204.160759] dht11: WARNING: decoding ambiguous
[  205.186935] iio iio:device0: Only 0 signal edges detected

저 값이 무슨 의미인지도 모르겠고.. (그냥 65% 24도로 보면되려나?)

잘 안읽히거나 연결 시간 초과로 읽는데 오래 걸리기도 하니까..

여러번 계속 읽어 봐야 한다. ㄷㄷㄷ



+

2015.09.09

그래도 어떤 사람은 75% 성공률로 읽는다는데.. 난 더 낮은 느낌?

[링크 : https://www.raspberrypi.org/forums/viewtopic.php?p=779355]


쓰레드로 된건 읽기 왜케 힘드냐 -_-

[링크 : http://www.spinics.net/lists/linux-iio/msg19328.html]

Posted by 구차니
embeded/raspberry pi2015. 9. 3. 09:13

생각해보니.. 음속은 기온에 비례하는데

공식으로는 대충


음속 = (331.3 + 0.606 * 섭씨) m/s

0도에서 약 331m인데

실온이면 약 18도 로 잡고(10.908m/s) 342.208m/s

근사치로 340 정도 잡으면 될거 같긴한데


[링크 : https://en.wikipedia.org/wiki/Speed_of_sound]


어짜피 DHT-11 온도/습도 센서가 있으니까..

이걸로 온도 잰걸로 음속을 환산해주면 좀더 정확해지려나? +_+


[링크 : http://eleparts.co.kr/EPXF6C83]

[링크 : http://eleparts.co.kr/EPXF43N9]


Posted by 구차니
embeded/i2c2015. 9. 2. 17:31

주소번지의 한계를 넘기기 위해 

일종의.. 페이징? 이라고 해야 하려나?


Bank Switching Operation

I2C can access 256 addresses directly (i.e. 0x00 through 0xFF).

SMBus can access 128 addresses directly (i.e. 0x00 through 0x7F).

NB3H5150 has an address space which goes up to 0x14F. Therefore, a “bank switching” mechanism is included to allow access to all addresses no matter which bus protocol is used. Effectively, the two bank select bits are appended to the most-significant end of the seven-bit byte offset, creating a nine-bit address. The bank switch control bits(6:7) are located in Register 0x21.

The most significant two bits of that register are used for bank selection; the least significant six bits are used for the READBYTECOUNT Function.


[링크 : http://www.onsemi.com/pub_link/Collateral/NB3H5150_I2C_MANUAL.PDF]

'embeded > i2c' 카테고리의 다른 글

i2c mode - tm4c  (0) 2018.04.26
i2c BUS에 pull-up, pull-down  (0) 2018.04.26
i2c 정리  (4) 2012.01.10
I2C  (2) 2011.11.28
SMBus 넌 머냐? - System Management Bus  (2) 2009.01.14
Posted by 구차니
embeded/raspberry pi2015. 9. 2. 16:23


CPU의 시리얼 번호를 기반으로 MAC을 생성 하는 듯?

그나저나.. BogoMIPS가 멋대로 바뀌네? ㄷㄷㄷ


타이머로 변경되면서 클럭 변경되면 다르게 나오려나?

$ cat /proc/cpuinfo

processor       : 0

model name      : ARMv7 Processor rev 5 (v7l)

BogoMIPS        : 38.40

Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm

CPU implementer : 0x41

CPU architecture: 7

CPU variant     : 0x0

CPU part        : 0xc07

CPU revision    : 5 


$ cat /proc/cpuinfo

processor       : 3

model name      : ARMv7 Processor rev 5 (v7l)

BogoMIPS        : 57.60

Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm

CPU implementer : 0x41

CPU architecture: 7

CPU variant     : 0x0

CPU part        : 0xc07

CPU revision    : 5


Hardware        : BCM2709

Revision        : a21041

Serial          : 00000000a37ce24e


$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq; cat /proc/cpuinfo

900000

processor       : 0

model name      : ARMv7 Processor rev 5 (v7l)

BogoMIPS        : 57.60

Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm

CPU implementer : 0x41

CPU architecture: 7

CPU variant     : 0x0

CPU part        : 0xc07

CPU revision    : 5


$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq; cat /proc/cpuinfo

600000

processor       : 0

model name      : ARMv7 Processor rev 5 (v7l)

BogoMIPS        : 38.40

Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm

CPU implementer : 0x41

CPU architecture: 7

CPU variant     : 0x0

CPU part        : 0xc07

CPU revision    : 5


---

라즈 B


# cat /proc/cpuinfo

processor       : 0

model name      : ARMv6-compatible processor rev 7 (v6l)

Features        : half thumb fastmult vfp edsp java tls

CPU implementer : 0x41

CPU architecture: 7

CPU variant     : 0x0

CPU part        : 0xb76

CPU revision    : 7


Hardware        : BCM2708

Revision        : 000e

Serial          : 0000000055593a15


# ifconfig

eth0      Link encap:Ethernet  HWaddr B8:27:EB:59:3A:15

---



$ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:7c:e2:4e
          inet addr:192.168.10.23  Bcast:192.168.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1685 errors:0 dropped:2 overruns:0 frame:0
          TX packets:358 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:107201 (104.6 KiB)  TX bytes:52547 (51.3 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1104 (1.0 KiB)  TX bytes:1104 (1.0 KiB)


$ cat /sys/class/net/eth0/address

b8:27:eb:7c:e2:4e


[링크 : http://www.robert-drummond.com/2013/05/23/how-to-find-the-mac-address-of-your-raspberry-pi/]

Posted by 구차니
embeded/raspberry pi2015. 8. 27. 08:24

자유낙하 실험... 은 아니고

가방에 넣어 두었는데

가방이 떨어지면서 먼가 불쾌한 철퍽 하는 소리..

꺼내보니 액정까진 아니고 액정 보호유리가 깨지고..

켜보니... ㅠㅠ


터치 축 틀어짐 -_-!!!!

캘리브레이션 한다고 될진 모르겠지만 끄아아아아 ㅠㅠ



사요나라

바이바이

잘가

ㅠㅠ





그러니 다시 사야하나? ㅠㅠ

[링크 : http://eleparts.co.kr/EPXDR9TM]

Posted by 구차니
embeded/ARM2015. 8. 26. 09:28

cortex-m3만 사용했는데 문득 M0 라던가 다른 모델군이 있는게 생각이 나서 검색..

일단은.. cortex-m3 는 그래도 나름! 풀 스펙에 가까운 표준형 cortex-m 시리즈라고 보면

M0는 숫자가 적은 만큼 마이너 버전이다.

그리고 M0/M1은 M3와 다르게 ARMv6 계열.. ㄷㄷㄷ

또한 Thumb 호환성도 조금 더 낮고(그래서 저전력/gate 수가 적다고)

결정적으로.. Hardware divider가 제외되어있다. 그나마 Hardware multiplier가 있는게 다행인가..


조금.. 의아한건..

M3/4/7이 Harvard 아키텍쳐인데 반해

M0/1은 폰 노이만으로의 회귀...


[링크 : https://en.wikipedia.org/wiki/Von_Neumann_architecture]

[링크 : https://en.wikipedia.org/wiki/Harvard_architecture]


[링크 : https://en.wikipedia.org/wiki/ARM_Cortex-M]


그런데 보다 보니 Saturated math라는게 보여서 링크를 따라가니.. 오홍.. 좋아 보이는데?!?!?!

간단하게 설명하면 더 큰 변수로 캐스팅, 계산 값 범위 비교, 클 경우 최대값 넣기

이 세가지를 한방에 끝내주는 연산이다. overflow로 인한 예측하지 못한 값에 의한 오류도 막아주고(물론 오차는 존재하지만)

if문에 의한 branch를 줄여주는 부분에서 상당한 장점이 있을 것으로 보인다.

[링크 : https://en.wikipedia.org/wiki/Saturation_arithmetic]

[링크 : http://www.arm.com/products/processors/cortex-m/]

'embeded > ARM' 카테고리의 다른 글

arm11 simd instruction  (0) 2015.10.01
cortex-A5/A7  (0) 2015.09.21
ARM926EJ / ARMv5TE  (0) 2015.07.28
Jazelle 관련 검색  (0) 2015.04.28
ltib 패키지 요구사항  (0) 2015.04.13
Posted by 구차니
embeded/raspberry pi2015. 8. 24. 15:47

아두이노랑은 이렇게 하라는데

일단.. I2C로 할거니까.. 저렇게 위에 4개 선을 연결하면 어찌어찌 라즈베리에서도 사용가능 할 듯



장치 ID는 0xE5 고정

ADXL345

REGISTER DEFINITIONS

Register 0x00—DEVID (Read Only)

The DEVID register holds a fixed device ID code of 0xE5 (345 octal). 



데이터는 X/Y/Z축 LSB / MSB 순으로 들어 있다.


Register 0x32 to Register 0x37—DATAX0, DATAX1, DATAY0, DATAY1, DATAZ0, DATAZ1 (Read Only)

 These six bytes (Register 0x32 to Register 0x37) are eight bits each and hold the output data for each axis. Register 0x32 and Register 0x33 hold the output data for the x-axis, Register 0x34 and Register 0x35 hold the output data for the y-axis, and Register 0x36 and Register 0x37 hold the output data for the z-axis. The output data is twos complement, with DATAx0 as the least significant byte and DATAx1 as the most significant byte, where x represent X, Y, or Z. The DATA_FORMAT register (Address 0x31) controls the format of the data. It is recommended that a multiple-byte read of all registers be performed to prevent a change in data between reads of sequential registers



I 2 C

 With CS tied high to VDD I/O, the ADXL345 is in I2 C mode, requiring a simple 2-wire connection, as shown in Figure 40. The ADXL345 conforms to the UM10204 I 2 C-Bus Specification and User Manual, Rev. 03—19 June 2007, available from NXP Semiconductors. It supports standard (100 kHz) and fast (400 kHz) data transfer modes if the bus parameters given in Table 11 and Table 12 are met. Single- or multiple-byte reads/writes are supported, as shown in Figure 41. With the ALT ADDRESS pin high, the 7-bit I 2 C address for the device is 0x1D, followed by the R/W bit. This translates to 0x3A for a write and 0x3B for a read. An alternate I2 C address of 0x53 (followed by the R/W bit) can be chosen by grounding the ALT ADDRESS pin (Pin 12). This translates to 0xA6 for a write and 0xA7 for a read. There are no internal pull-up or pull-down resistors for any unused pins; therefore, there is no known state or default state for the CS or ALT ADDRESS pin if left floating or unconnected. It is required that the CS pin be connected to VDD I/O and that the ALT ADDRESS pin be connected to either VDD I/O or GND when using I2 C


[링크 : http://eleparts.co.kr/data/design/product_file/SENSOR/G_SENSOR/data/ADXL345.pdf]


---





---

pi@raspberrypi /boot/overlays $ dmesg | grep i2c

[    3.862054] bcm2708_i2c_init_pinmode(1,2)

[    3.863939] bcm2708_i2c_init_pinmode(1,3)

[    3.866020] bcm2708_i2c 3f804000.i2c: BSC1 Controller at 0x3f804000 (irq 79) (baudrate 100000)


pi@raspberrypi /boot/overlays $ lsmod | grep i2c

i2c_bcm2708             4990  0


pi@raspberrypi /boot/overlays $ insmod i2c-dev

Error: could not load module i2c-dev: No such file or directory


pi@raspberrypi /boot/overlays $ sudo vi /etc/modules

i2c-dev

i2c-bcm2708


pi@raspberrypi ~ $ lsmod | grep i2c

i2c_dev                 6027  0

i2c_bcm2708             4990  0


pi@raspberrypi ~ $ i2cdetect -y 1

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

00:          -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

50: -- -- -- 53 -- -- -- -- -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- --

pi@raspberrypi ~ $ i2cdetect -y 0

Error: Could not open file `/dev/i2c-0' or `/dev/i2c/0': No such file or directory


pi@raspberrypi ~ $ i2cdetect -l

i2c-1   i2c             3f804000.i2c                            I2C adapter


pi@raspberrypi ~ $ i2cdetect -F 1

Functionalities implemented by /dev/i2c-1:

I2C                              yes

SMBus Quick Command              yes

SMBus Send Byte                  yes

SMBus Receive Byte               yes

SMBus Write Byte                 yes

SMBus Read Byte                  yes

SMBus Write Word                 yes

SMBus Read Word                  yes

SMBus Process Call               yes

SMBus Block Write                yes

SMBus Block Read                 no

SMBus Block Process Call         no

SMBus PEC                        yes

I2C Block Write                  yes

I2C Block Read                   yes


pi@raspberrypi ~ $ lsmod | grep -i i2c

i2c_dev                 6027  0

i2c_bcm2708             4990  0



insmod가 아니라 modprobe ...


pi@raspberrypi ~ $ sudo modprobe i2c_dev

pi@raspberrypi ~ $ lsmod | grep i2c

i2c_dev                 6027  0

i2c_bcm2708             4990  0


[링크 : http://raspberrypi.stackexchange.com/.../how-to-make-raspbian-load-the-i2c-dev-module-on-boot-up]



---





#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <iostream>

int main(int argc, char **argv)
{
   printf("**** ADXL435 example program ****\n");
   
   int fd;                                          // File descrition
   char *fileName = "/dev/i2c-1";                        // Name of the port we will be using
   int  address = 0x53;                              // Address of the SRF02 shifted right one bit
   char buf[6];                              // Buffer for data being read/ written on the i2c bus
   short x,y,z;

   if ((fd = open(fileName, O_RDWR)) < 0) {               // Open port for reading and writing
      printf("Failed to open i2c port\n");
      exit(1);
   }
   
   if (ioctl(fd, I2C_SLAVE, address) < 0) {               // Set the port options and set the address of the device we wish to speak to
      printf("Unable to get bus access to talk to slave\n");
      exit(1);
   }

   buf[0] = 0x2d;                                       // Commands for performing a ranging
   buf[1] = 0x18;
   
   if ((write(fd, buf, 2)) != 2) {                        // Write commands to the i2c port
      printf("Error writing to i2c slave\n");
      exit(1);
   }

   buf[0] = 0x31;                                       // Commands for performing a ranging
   buf[1] = 0x09;
   
   if ((write(fd, buf, 2)) != 2) {                        // Write commands to the i2c port
      printf("Error writing to i2c slave\n");
      exit(1);
   }

                                       // This sleep waits for the ping to come back
while(true){   

   buf[0] = 0x32;                                       // This is the register we wish to read from
   if ((write(fd, buf, 1)) != 1) {                        // Send the register to read from
      printf("Error writing to i2c slave\n");
      exit(1);
   }
   

usleep(1000);
  memset(&buf,0,sizeof(buf));

   if (read(fd, buf, 6) != 6) {                        // Read back data into buf[]
      printf("Unable to read from slave\n");
      exit(1);
   }
   else { x=y=z=0;
//               memset(&buf,0,sizeof(buf));

      x = ((short)buf[1]<<8) | (short) buf[0]; 
       y = ((short)buf[3]<<8) | (short) buf[2];
       z = ((short)buf[5]<<8) | (short) buf[4];
       std::cout<<"x:"<<x<<"\ty:"<<y<<"\tz:"<<z<<std::endl;
   }
}
   return 0;

} 



Posted by 구차니