sixgod

ADIS16405 Communication with Raspberry Pi

Discussion created by sixgod on Jan 20, 2018
Latest reply on Jan 23, 2018 by NevadaMark
Branched from an earlier discussion

dear  NevadaMark:

this is my program:

 


#include <bcm2835.h>
#include <stdio.h>
#include <iostream>
#include <assert.h>
#include <math.h>
#include <unistd.h>

int main(int argc, char **argv)
{
using namespace std;

if (!bcm2835_init())
{
printf("bcm2835_init failed. Are you running as root??\n");
return 1;
}
if (!bcm2835_spi_begin())
{
printf("bcm2835_spi_begin failed. Are you running as root??\n");
return 1;
}
bcm2835_spi_begin(); ////启动spi接口,设置spi对应管脚为复用功能
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); //高位先传输
bcm2835_spi_setDataMode(BCM2835_SPI_MODE3); //spi模式3
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_16384); //? //分频
bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // 设置片选
bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); //设置片选低电平有效


while(1)
{
char buf[] = { 0x00, 0x3e}; // Data to send
bcm2835_spi_transfern(buf, sizeof(buf));
//usleep(50);
for(int i=0;i<13;i++)
{
buf[0]=0x00; // Data to send
buf[1]=0x00;
bcm2835_spi_transfern(buf, sizeof(buf));
printf("%02X%02X ", buf[1], buf[0]);

}

printf("\n");
}


bcm2835_spi_end();
bcm2835_close();
cin.get();
return 0;
}

 

 

 

This is my program with raspberryPI 3B,but I can not get the right data from 16405.

I can get the product ID,0x4015

I have  debugging it for many days,Please help me,thanks

 

NING

Outcomes