Hello,
I am a newbie and recently doing my project with ADS1298 and trying as first step to power the ADS1298EVM (without MMB0) by Raspberry Pi 2 Board (I am not sure if it is possible?). Im trying to build SPI between them (ADS as Slave, Raspberry Pi as Master). But i didnt get the result that i expected when i read the ID device. My SPI connections look like this:
Raspberry ADS1298EVM
3.3V ----- Pin 9 (on J4)
GND ----- Pin 6 (on J4)
Pin 23 (SCLK) ------ Pin 3 (CLK) (on J3)
Pin 24 (CE0) ------- Pin 7 (CS) (on J3)
Pin 19 (MOSI) ------- Pin 11 (DIN) (on J3)
Pin 21 (MISO) ------- Pin 13 (DOUT) (on J3)
Pin 12 (GPIO 18) ------- Pin 8 (RESETB) (on J3)
and here is my code ussing BCM2835 Library :
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
#include <stdio.h>
#include <bcm2835.h>
#include "/home/pi/Desktop/ADS1298.h"
#define CS_PIN RPI_BPLUS_GPIO_J8_24 //CS pin CE0
#define RESET_PIN RPI_BPLUS_GPIO_J8_12 //GIPO pin 18
#define MOSI_SPI RPI_BPLUS_GPIO_J8_19 //MOSI | GPIO 10
#define MISO_SPI RPI_BPLUS_GPIO_J8_21 //MISO | GPIO 9
#define CS_DELAY 5
void cs_select()
{
bcm2835_gpio_clr(CS_PIN);
}
void cs_deselect()
{
bcm2835_gpio_set(CS_PIN);
}
int main(int argc, char **argv)
{
char buffer[3];
if(!bcm2835_init())
{
return 1;
}
bcm2835_spi_begin();
bcm2835_gpio_fsel(RESET_PIN, BCM2835_GPIO_FSEL_OUTP); //set RESET_PIN as an output
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); //set bit Order
bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE); //do not set CS automatically
//bcm2835_gpio_fsel(MOSI_SPI, BCM2835_GPIO_FSEL_OUTP); //set MOSI_SPI as an output
//bcm2835_gpio_fsel(MISO_SPI, BCM2835_GPIO_FSEL_INPT); //set MISO_SPI as an input
bcm2835_gpio_fsel(CS_PIN, BCM2835_GPIO_FSEL_OUTP); // set CS_PIN as an output
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_16); //1.2 MHz
bcm2835_spi_setDataMode(BCM2835_SPI_MODE1);
//reset the device
bcm2835_gpio_write(RESET_PIN, LOW);
delay(2);
bcm2835_gpio_write(RESET_PIN, HIGH);
delay(128); //0.128s required
buffer[0]=(RREG | ID);
buffer[1]=0x00;
buffer[2]=0x00;
printf("Before spi_transfern:\n");
printf("Hexa value of buffer[0] = %x \n", buffer[0]);
printf("Hexa value of buffer[1] = %x \n", buffer[1]);
printf("Hexa value of buffer[2] = %x \n\n", buffer[2]);
cs_select();
bcm2835_spi_transfer(SDATAC);
bcm2835_delayMicroseconds(CS_DELAY);
cs_deselect();
bcm2835_delayMicroseconds(5);
cs_select();
bcm2835_spi_transfern(buffer,3);
bcm2835_delayMicroseconds(CS_DELAY);
cs_deselect();
printf("After spi_transfern:\n");
printf("Hexa value of buffer[0] = %x \n", buffer[0]);
printf("Hexa value of buffer[1] = %x \n", buffer[1]);
printf("Hexa value of buffer[2] = %x \n", buffer[2]);
bcm2835_spi_end();
return 0;
}
Wiring 2 device:
But i only get this rerult :
And then this when i took the 2 power connections out from Raspi to J4 on ADS1298:
It seems like the value changed sometimes somehow when i connect and reconnect the 2 power wires to J4. As prove i have got this result after i put the power wires on J4 again: