Borrar filtros
Borrar filtros

Raspberry Pi Interface with ADS1256

11 visualizaciones (últimos 30 días)
Francis B.
Francis B. el 27 de En. de 2018
Comentada: Francis B. el 5 de Feb. de 2018
I am attempting to integrate an ADS1256 (link to TI: ADS1256 ) with my Raspberry Pi. I purchased this board to do the hardware interfacing and would like to use MATLAB to do the rest. I am executing the following code:
mypi = raspi;
enableSPI(mypi);
myADS1256 = spidev(mypi,'CE0',1,2000000);
to read/write to some registers, however I am having a difficult time read/writing to registers successfully every time. I believe is because I am not 100% certain of the SPI Bus speed (fCLKIN = 7.68MHz is the clock of the ADS1256). I have tried multiple bus speed with some not working at all and others working only half the time. Any help would be appreciated.
The following command I am using to read the status:
status = writeRead(myADS1256,[bin2dec('00010000'), bin2dec('00000000')]); %read status
The following command I am using to read the data rate:
dataRate = writeRead(myADS1256,[bin2dec('00010011'),bin2dec('00000000')]); % read data rate
The following command I am using to write a new data rate:
setDataRate = writeRead(myADS1256,[bin2dec('01010011'), bin2dec('00000000'), bin2dec('00100011')]); % setting data rate to 10SPS ('00100011')
and I re-read the data rate to confirm the register was written to.
  1 comentario
Francis B.
Francis B. el 1 de Feb. de 2018
After looking at the specification sheet for the ADS1256, the bus speed needs to be set to 500000 or 1000000 Hz. This based on being fclkin = 7.68 MHz and SCLK must be less than fclkin/4. It is still unknown why I am only receiving intermittent responses to requesting status and data rate.

Iniciar sesión para comentar.

Respuesta aceptada

Francis B.
Francis B. el 4 de Feb. de 2018
Editada: Francis B. el 5 de Feb. de 2018
I am successful if I send a wake command after every writeRead... A wake command looks like:
status = writeRead(myADS1256,0);
So my startup code looks like:
status = writeRead(myADS1256,[bin2dec('00010000'), 0]); %read status
status = writeRead(myADS1256,0);
dataRate = writeRead(myADS1256,[bin2dec('00010011'), 0]); % read data rate
dataRate = writeRead(myADS1256,0); % original data rate should equal 240 or '11110000'
if dataRate == 240
fprintf('ADS1256 Data Rate: 30000 SPS\n');
end
setStatus = writeRead(myADS1256,[bin2dec('01010000'), 0, bin2dec('00110100')]); % setting auto calibration on
pause(0.4); % Self calibration takes approximately 300 ms for 10 SPS
setStatus = writeRead(myADS1256,0);
statusNew = writeRead(myADS1256,[bin2dec('00010000'),0]); %read status
statusNew = writeRead(myADS1256,0);
if statusNew == 52
fprintf('ADS1256 Auto Calibrated\n');
end
setDataRate = writeRead(myADS1256,[bin2dec('01010011'), 0, bin2dec('00100011')]); % setting data rate to 10SPS ('00100011')
setDataRate = writeRead(myADS1256,0);
dataRateNew = writeRead(myADS1256,[bin2dec('00010011'),0]); % read data rate
dataRateNew = writeRead(myADS1256,0);
if dataRateNew == 35
fprintf('ADS1256 Data Rate: 10 SPS\n');
end
setADCON = writeRead(myADS1256,[bin2dec('01010010'), 0, bin2dec('00000000')]); % setting ADCON register,
setADCON = writeRead(myADS1256,0);
ADCONNew = writeRead(myADS1256,[bin2dec('00010010'),0]); %read ADCON register
ADCONNew = writeRead(myADS1256,0);
if ADCONNew == 0
fprintf('ADS1256 A/D Control Register Set\n');
end
setStatus = writeRead(myADS1256,[bin2dec('01010000'), 0, bin2dec('00110000')]); % setting auto calibration off
pause(0.4); % Self calibration takes approximately 300 ms for 10 SPS
setStatus = writeRead(myADS1256,0);
statusNew = writeRead(myADS1256,[bin2dec('00010000'),0]); %read status
statusNew = writeRead(myADS1256,0);
if statusNew == 48
fprintf('ADS1256 Auto Calibration Off\n');
end
To actually read data in its a bit more tricky:
x = 0;
while x == 0
volts = zeros(8,1);
for i = 1:8
nibble_0 = '1000'; % sets negative to be common ground
switch i
case 1
nibble_1 = '0000'; % ain #0
case 2
nibble_1 = '0001'; % ain #1
case 3
nibble_1 = '0010'; % ain #2
case 4
nibble_1 = '0011'; % ain #3
case 5
nibble_1 = '0100'; % ain #4
case 6
nibble_1 = '0101'; % ain #5
case 7
nibble_1 = '0110'; % ain #6
case 8
nibble_1 = '0111'; % ain #7
end
muxSelect = [nibble_1,nibble_0];
setMux = writeRead(myADS1256,[bin2dec('01010001'), 0, bin2dec(muxSelect)]); % selecting appropriate mux
sync = writeRead(myADS1256,bin2dec('11111100')); % syncing a/d conversion
pause(1/(7.68*1000000*4)); % pause
wakeup = writeRead(myADS1256,0); % wake command
readDataOnceCommand = writeRead(myADS1256,bin2dec('00000001')); %read data once
readDataOnce(1:3) = writeRead(myADS1256,[0,0,0]);
binReadDataOnce_1 = dec2bin(readDataOnce(1));
while length(binReadDataOnce_1) < 8
binReadDataOnce_1 = ['0', binReadDataOnce_1]; % padding with zeros
end
binReadDataOnce_2 = dec2bin(readDataOnce(2));
while length(binReadDataOnce_2) < 8
binReadDataOnce_2 = ['0', binReadDataOnce_2]; % padding with zeros
end
binReadDataOnce_3 = dec2bin(readDataOnce(3));
while length(binReadDataOnce_3) < 8
binReadDataOnce_3 = ['0', binReadDataOnce_3]; % padding with zeros
end
binaryValue = [binReadDataOnce_1,binReadDataOnce_2,binReadDataOnce_3];
if strcmp(binaryValue(1),'1') % negative value lookup
negativeCount = bin2dec(binaryValue);
counts = negativeCount-2^24;
else
counts = bin2dec(binaryValue);
end
volts(i) = counts*2*2.5/(1*(2^23 - 1)); % LSB == 2*VREF/(PGA*(2^23 − 1)).
DRDYValue = readDigitalPin(mypi,17);
while DRDYValue % wait until DRDY is false
DRDYValue = readDigitalPin(mypi,17);
end
end
ain = [volts(2:8); volts(1)] % prints to workspace in the correct order (since this reads previous readWrite command
end
  2 comentarios
Walter Roberson
Walter Roberson el 5 de Feb. de 2018
By the way, your sections such as
while length(binReadDataOnce_2) < 8
binReadDataOnce_2 = ['0', binReadDataOnce_2]; % padding with zeros
end
can be avoided by changing
binReadDataOnce_1 = dec2bin(readDataOnce(1));
to
binReadDataOnce_1 = dec2bin(readDataOnce(1), 8);
Francis B.
Francis B. el 5 de Feb. de 2018
Thanks Walter!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Support Package for Raspberry Pi Hardware en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by