Raspberry Pi > C > RPi_i2c_comm_180227: v1.0 > 센서에서 데이터를 읽을 때까지 | 비 RPi로 이식 및 작동
Raspberry Pi 2 Model B (以下RPi)
Raspbian Jessie
gcc (Raspbian 4.9.2-10) 4.9.2
とあるI2Cセンサー
Raspberry Pi > C > RPi_i2c_comm_180227: v0.4 > GPIO 핀 레벨 설정 및 레벨 읽기까지
계속.
어떤 I2C 센서의 판독까지 구현할 수 있었다.
GitHub 리포지토리
v1.0 @ GitHub
처리 개요
위의 핀과 VCC, GND 핀을 사용하여 소프트웨어 I2C로 센서에서 데이터를 얻는다.
RPi_i2c_comm_180227.c
...
int main(void)
{
int slvAdr = 0x44; // Slave address
char vals[10] = {0};
int idx;
//test_clockout_ioin();
// 1. init
i2c_Setup();
// 2. start measurement
// write header
i2c_SendStartCondition(/* withInit=*/true);
i2c_SendSlaveAddress(slvAdr, /*bfRead=*/false);
if (i2c_IsACK()) {
printf("ACK\n");
};
// send command
i2c_SendData(0x2C); // 0x2C: arbitrary
if (i2c_IsACK()) {
printf("ACK\n");
};
i2c_SendData(0x06); // 0x06: arbitrary
if (i2c_IsACK()) {
printf("ACK\n");
};
i2c_SendStopCondition();
// 3. wait for measurement
Wait_millisecond(15); // 15: arbitrary
// 4. obtain data
// read header
i2c_SendStartCondition(/* withInit=*/false);
i2c_SendSlaveAddress(slvAdr, /*bfRead=*/true);
if (i2c_IsACK()) {
printf("ACK\n");
};
for(idx=0; idx<6; idx++) {
vals[idx] = i2c_ReadData(/* isLast=*/(idx==5));
printf("%d\n", vals[idx]);
}
i2c_SendStopCondition();
// 5. finish
i2c_Teardown();
return 0;
}
소스 구성
RPi 이외의 이식 이하와 같이 함으로써, RPi 이외에서의 실장이 가능했다. i2c_gpio_180309 다음을 다시 작성 wait_msec_nsec_180301 다음을 다시 작성 RPi_i2c_comm_180227의 main() 함수에서 처리 구현 파일 종료를 CR+LF로 설정(Windows의 경우) 다음은 RPi 이외의 센서에서 읽은 결과입니다. 이식 직후 클럭 설정에 실패했지만, Analog Discovery 2에서 응답을 확인하면서 디버그하자마자 해결했다.

DIO 11은 사용하지 않는 핀. Analog Discovery2 경고 메시지가 I2C 라인 그리기와 겹치기 위한 조치.
이것으로 [RPi로 동작 확인] > [임베디드로 구현]의 흐름이 완성되었다.
비고
linux상에서 만든 소스를 Windows상의 임베디드 개발 환경에서 사용하려고 하면 「종단 코드가 특수합니다」와 같은 메시지가 표시된다.
linux에서는 LF의 종단으로, Windows에서는 CR+LF의 종단의 차이에 기인한다.
Reference
이 문제에 관하여(Raspberry Pi > C > RPi_i2c_comm_180227: v1.0 > 센서에서 데이터를 읽을 때까지 | 비 RPi로 이식 및 작동), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/7of9/items/09e3c4627cd030da0276텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)