Hey All,
Currently, I am making a pulse oximetre using AFE4490 by Texas Instrument and arduino Mega 2560.
I have a problem relating to the SPI communication in arduino.
This SPI communication is required to make a writing and reading register module.
So, I am making its function for both writing and reading register. The writing seems good, but the reading might be confusing for me.
I write it like this
unsigned long AFE4490Read (unsigned char address)
{
SPIInit();
digitalWrite (SPISTE, LOW);
byte data = shiftIn (SOMI, SCLK, LSBFIRST);
///////////data 0/////////////
shiftOut (SIMO, SCLK, LSBFIRST, 0X00); /*SIMO shifting out byte module */
byte data0 = shiftIn (SOMI, SCLK, LSBFIRST);
data0 = (data&0X000F);
delay(20);
///////////data 1/////////////
shiftOut (SIMO, SCLK, LSBFIRST, 0X00); /*SIMO shifting out byte module */
byte data1 = shiftIn (SOMI, SCLK, LSBFIRST);
data1 = (data >>4)& (0X00F);
delay(20);
///////////data 2/////////////
shiftOut (SIMO, SCLK, LSBFIRST, 0X00); /*SIMO shifting out byte module */
byte data2 = shiftIn (SOMI, SCLK, LSBFIRST);
data2 = (data >>8)& (0XF);
delay(20);
///////////data 3/////////////
shiftOut (SIMO, SCLK, LSBFIRST, address); /*SIMO shifting out byte module */
byte data3 = 0X00;
data3 = shiftIn (SOMI, SCLK, LSBFIRST);
SPI.end();
digitalWrite (SPISTE, HIGH);
}
So the reading procedure is happened by sending 32 bits, the three first 8-bits will be sent to arduino MISO and will be recognized as data bit register, meanwhile the last 8-bits will be sent to the AFE4490 and will be recognized as an address register bit.
I understand how to sending out the value using shiftOut, but I am not sure how i should write in in order to read the MISO data in arduino. So far, I am sketching the MISO data reading as shown above. But, I don't it works properly.
Please suggest me how to do this.
Thank you in advance!
Stella