ujjwalrathod007
Posts: 91
Joined: Thu Dec 22, 2016 10:09 am

WiringPi interfacing with Infineon pressure sensor dps310 not working

Mon Jun 10, 2019 1:33 pm

I am trying to use WiringPi since last 2 days and finding some hard time to get the data. following is my code in Wiringpi. The output of read value always stays the same even though I access diffrent registers.. i.e. 255(xFF).

Why such an error?

Code: Select all

#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>

static const int CHANN=0;

int main()
{
	unsigned char buffer[100],result;
	buffer[0] = 0x80;	//register address
	wiringPiSetup();
	wiringPiSPISetup(CHANN, 500000);
	pinMode(10,OUTPUT);	//MOSI
	pinMode(11,OUTPUT);	//SCLK
	pinMode(9,INPUT);	//MISO
	pinMode(8,OUTPUT);	//CS
	digitalWrite(8,HIGH); //make cs high
	delay(10);
	digitalWrite(8,LOW);// Chip select
	delay(10);
	//loop();
	result=wiringPiSPIDataRW(CHANN, buffer[0],1);
	printf("\n%d\n",result);
	printf("\n%d",buffer[0]);
	digitalWrite(8,HIGH);
	}

User avatar
joan
Posts: 13999
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: WiringPi interfacing with Infineon pressure sensor dps310 not working

Mon Jun 10, 2019 3:42 pm

You are mucking about with the SPI GPIO modes. Why?

You have taken them out of SPI mode and made them ordinary GPIO in input and output mode. You need to leave them in the mode set by the kernel SPI driver.

ujjwalrathod007
Posts: 91
Joined: Thu Dec 22, 2016 10:09 am

Re: WiringPi interfacing with Infineon pressure sensor dps310 not working

Mon Jun 10, 2019 3:55 pm

I have also tried without those pinmodes only like this....but still the same results

Code: Select all


int main()
{
	unsigned char buffer[100],result;
	buffer[0] = 0x8D;
	wiringPiSetup();
	wiringPiSPISetup(CHANN, 500000);
	result=wiringPiSPIDataRW(CHANN, buffer[0],1);
	printf("\n%d\n",result);
	printf("\n%d",buffer[0]);
	digitalWrite(8,HIGH);
	}

User avatar
joan
Posts: 13999
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: WiringPi interfacing with Infineon pressure sensor dps310 not working

Mon Jun 10, 2019 4:13 pm

Have you rebooted? Otherwise the GPIO will be in the wrong mode.

If it still doesn't work your wiring is likely to be wrong.

ujjwalrathod007
Posts: 91
Joined: Thu Dec 22, 2016 10:09 am

Re: WiringPi interfacing with Infineon pressure sensor dps310 not working

Thu Jun 13, 2019 10:56 am

I think My wiring is also correct. I tried a similar sensor and protocol but there are some problems Image
Image

User avatar
joan
Posts: 13999
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: WiringPi interfacing with Infineon pressure sensor dps310 not working

Thu Jun 13, 2019 11:16 am

https://ibb.co/9q6006R
https://imgur.com/yvRWW7y

I can't make out the connections.

Could you summarise Pi pin to sensor pin?

ujjwalrathod007
Posts: 91
Joined: Thu Dec 22, 2016 10:09 am

Re: WiringPi interfacing with Infineon pressure sensor dps310 not working

Thu Jun 13, 2019 2:08 pm

Yes sure, I am using Raspberry pi 3 B...

I have two different sensors both are SPI.

VIN>3.3V
GND>GND

MISO> GPIO 9 (pin 21)
MOSI> GPIO 10 (pin 19) (this pin only incase of pressure sensor dps310)
SCLK> GPIO 11(pin 23)
CS> GPIO 8(pin 24)

User avatar
joan
Posts: 13999
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: WiringPi interfacing with Infineon pressure sensor dps310 not working

Thu Jun 13, 2019 4:55 pm

In your code you have buffer[0]. The expected parameter is an address so that should be &buffer[0] or buffer.

ujjwalrathod007
Posts: 91
Joined: Thu Dec 22, 2016 10:09 am

Re: WiringPi interfacing with Infineon pressure sensor dps310 not working

Thu Jun 13, 2019 7:01 pm

The code will not compile and run if I had that mistake :lol: :) . I had changed that in the next sensor, I can see in my code. well, the result is the same... still
well the datasheet says that it should be a 16-bit word, Only transmitted by a sensor on regular time. So no MOSI only MISO is connected. I set buffer[0] and buffer[1] to 0x00. :P :P . In reply from sensor, I get 226 and 226 for both buffers which corresponds to (11100010)... which is weird and undesired behavior. FYI I also tried DigitalRead() function and << buffer. same 226 is there.

https://www.infineon.com/dgdl/Infineon- ... 43ca0938a4
Will try the other sensor letter.

Code: Select all

include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>

static const int CHANN=0;

int main()
{
	
	unsigned char buffer[1000];
	buffer[0] = 0x00;
	printf("\n%d", buffer[0]);
	buffer[1]=0x00;
	
	wiringPiSetup();
	wiringPiSPISetup(CHANN, 500000);
	wiringPiSPIDataRW(CHANN, &buffer[0], 1);
	wiringPiSPIDataRW(CHANN, &buffer[1], 1) ;
	
	printf("\n%d", buffer[0]);
	printf("\n%d", buffer[1]);
		
	}

User avatar
joan
Posts: 13999
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: WiringPi interfacing with Infineon pressure sensor dps310 not working

Thu Jun 13, 2019 7:45 pm

Instead of

Code: Select all

wiringPiSPIDataRW(CHANN, &buffer[0], 1);
wiringPiSPIDataRW(CHANN, &buffer[1], 1) ;
try

Code: Select all

wiringPiSPIDataRW(CHANN, &buffer, 2);

ujjwalrathod007
Posts: 91
Joined: Thu Dec 22, 2016 10:09 am

Re: WiringPi interfacing with Infineon pressure sensor dps310 not working

Fri Jun 14, 2019 7:40 am

Thank you. I had tried it worked. It seems to get some data which makes sense.


How did you realize to send &buffer? Is it if I send it separately there is some delay? hence the sensor data is not the one which I want?

Code: Select all

wiringPiSPIDataRW(CHANN, &buffer[0], 1);
wiringPiSPIDataRW(CHANN, &buffer[1], 1) ;

User avatar
joan
Posts: 13999
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: WiringPi interfacing with Infineon pressure sensor dps310 not working

Fri Jun 14, 2019 7:55 am

It is simpler than that. Most SPI devices reset their state machine when their chip select changes level. The SPI hardware asserts/deasserts chip select for each SPI transfer.

Return to “Interfacing (DSI, CSI, I2C, etc.)”