Hi,
I am currently using the ADS1299 with the Beagleboard Black. I am not very familiar with SPI communication. That' s why I am trying to begin with easy stuff like just read the device id of the ads1299 with the BB.
My current wiring in the ads1299 side is :
- CS0 -> pin 39
- Doutput -> pin 43
- Dinput -> pin 34
- SCLK -> pin 40
- AVDD -> pin 56 (+5V)
- AVSS -> pin 57 (-5V)
- DVDD -> pin 50 (+3.3V)
- DGND -> pin 49 (-3.3V)
I wrote my own piece of code in C using spidev to read device id but I was only able to read FF in the answer from ADS1299. My current process is to send SDATAC,then RESET then use the RREG command on the first register to try to get device register id. Because I am not able to understand if it is a software or wiring issue, I also tried with a piece of code find on this forum on this post : http://e2e.ti.com/support/data_converters/precision_data_converters/f/73/t/351973.aspx
After some modification to fetch ads1299 instead of ads1256 and my current need, the code is :
int spi_init (int *fd, uint8_t *mode, uint8_t *bits, uint32_t *speed, char *device) { int ret=0; //Open device (*fd) = open(device, O_RDWR); if (fd < 0) return -1; //SPI Mode ret = ioctl((*fd), SPI_IOC_WR_MODE, mode); if (ret == -1) return -2; ret = ioctl((*fd), SPI_IOC_RD_MODE, mode); if (ret == -1) return -3; //Bits per word ret = ioctl((*fd), SPI_IOC_WR_BITS_PER_WORD, bits); if (ret == -1) return -4; ret = ioctl((*fd), SPI_IOC_RD_BITS_PER_WORD, bits); if (ret == -1) return -5; //Max speed in Hz ret = ioctl((*fd), SPI_IOC_WR_MAX_SPEED_HZ, speed); if (ret == -1) return -6; ret = ioctl((*fd), SPI_IOC_RD_MAX_SPEED_HZ, speed); if (ret == -1) return -7; return 0; } int main (int argc, char *argv[]) { int fd,opt,ret=0,res=0; char device[MAX_BUF]="/dev/spidev1.0"; uint32_t speed=1000000, dummy; uint8_t mode=1, bits=8, spiregister[10],spivalue[2],rx[ARRAY_SIZE(spiregister)] = {0,0,0,0,0}; unsigned short int delay =10; unsigned char repeated_iteration = 0; struct spi_ioc_transfer tr = { .tx_buf = (unsigned long)spiregister, .rx_buf = (unsigned long)rx, .len = ARRAY_SIZE(spiregister), .delay_usecs = delay, .speed_hz = speed, .bits_per_word = bits, }; //Init_SPI res=spi_init(&fd, &mode, &bits, &speed, device); if (res==-1) pabort("can't open device"); if (res==-2) pabort("WRITE: can't set spi mode"); if (res==-3) pabort("READ: can't get spi mode"); if (res==-4) pabort("WRITE: can't set bits per word"); if (res==-5) pabort("READ: can't get bits per word"); if (res==-6) pabort("WRITE: can't set max speed hz"); if (res==-7) pabort("READ: can't get max speed hz"); //Show SPI Information printf("spi mode: %d\n", mode); printf("bits per word: %d\n", bits); printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); printf("spidev node: %s\n", device); deg("TI-ADS1299 Configuring\n"); spiregister[0] = 0x11; //SDATAC Command ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); if (ret < 1) pabort("Config : can't send spi message"); usleep(100); /****** RESET ******/ spiregister[0] = 0x06; //RESET Command ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); if (ret < 1) pabort("Config : can't send spi message"); usleep(100); deg("Reading the Value\n\n\n"); int data; while(1) { spiregister[0] = 0x20; //RDATA ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); if (ret < 1) pabort("Config : can't send spi message"); sleep(1); printf("MSB = %.2X\n",rx[1]); data = rx[1]; printf("DATA = %.2X\n",rx[2]); data = (data << 8) | rx[2]; printf("LSB = %.2X\n",rx[3]); data = (data << 8) | rx[3]; } close(fd); return 0; }
I am only able to read FF in the answer again.... Is there any issue in my current wiring or code ?
Thanks & Regards,
Arthur.