ads1259

Dependents:   Chromatograph_Mobile Chromatograph_Mobile

Committer:
vitlog
Date:
Mon Jun 22 09:51:45 2020 +0000
Revision:
1:533ce2102fcc
Parent:
0:f9ba28ab9f4c
ne pomnyu chto pomenyal

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vitlog 0:f9ba28ab9f4c 1 #include "ADS1259.h"
vitlog 0:f9ba28ab9f4c 2 #include "PGA280.h"
vitlog 0:f9ba28ab9f4c 3 #include "PGA280ADS1259.h"
vitlog 0:f9ba28ab9f4c 4 #include <math.h>
vitlog 0:f9ba28ab9f4c 5
vitlog 0:f9ba28ab9f4c 6
vitlog 0:f9ba28ab9f4c 7 //#include "app.h"
vitlog 0:f9ba28ab9f4c 8 //counter; //сделать переменную видимой в этом файле
vitlog 0:f9ba28ab9f4c 9 void pga280_ads1259_init ( unsigned char ch )
vitlog 0:f9ba28ab9f4c 10 {
vitlog 0:f9ba28ab9f4c 11 pga280_resetDevice ( ch );
vitlog 0:f9ba28ab9f4c 12 //ads1259_resetDevice ( ch ); //микросхема снова уходит в сброс как только сменится адрес, так как ножка RESET оключается
vitlog 0:f9ba28ab9f4c 13 /*Сюда вставить задержку не менее 20 мс (для того чтобы микросхема АЦП раскачалась)*/
vitlog 0:f9ba28ab9f4c 14 pga280_ads1259_setup_pga280(ch);
vitlog 0:f9ba28ab9f4c 15 wait_ms(100); /*задержка перед настройкой АЦП*/
vitlog 0:f9ba28ab9f4c 16 pga280_ads1259_setup_ads1259(ch);
vitlog 0:f9ba28ab9f4c 17 }
vitlog 0:f9ba28ab9f4c 18
vitlog 0:f9ba28ab9f4c 19 void pga280_ads1259_setup_pga280 ( unsigned char ch )
vitlog 0:f9ba28ab9f4c 20 /*Предварительная настройка PGA280 (Это инициализация по идее)*/
vitlog 0:f9ba28ab9f4c 21
vitlog 0:f9ba28ab9f4c 22 {
vitlog 0:f9ba28ab9f4c 23 //PGA280_INPUT_SWITCH0.SW_A1=1;
vitlog 0:f9ba28ab9f4c 24 //PGA280_INPUT_SWITCH0.SW_A2=1;
vitlog 0:f9ba28ab9f4c 25 pga280_writeOneRegisterDevice ( PGA280_INPUT_SWITCH0_ADR, 0x18, ch ); //выбрать для работы INP2 INN2
vitlog 0:f9ba28ab9f4c 26 pga280_writeOneRegisterDevice ( PGA280_INPUT_SWITCH1_ADR, 0, ch );
vitlog 0:f9ba28ab9f4c 27 pga280_writeOneRegisterDevice ( PGA280_GPIO_DIR_ADR, 0b111111, ch ); //установить первые 6 выводов на выход
vitlog 0:f9ba28ab9f4c 28 pga280_writeOneRegisterDevice ( PGA280_CS_MODE_ADR, 0b00010000, ch ); //ECS4 в расширенном CS режиме
vitlog 0:f9ba28ab9f4c 29 pga280_writeOneRegisterDevice ( PGA280_SP_FUNCTION_ADR,7 , ch );//выводы GPIO0-2 используются для функции MUX
vitlog 0:f9ba28ab9f4c 30 }
vitlog 0:f9ba28ab9f4c 31
vitlog 0:f9ba28ab9f4c 32 void pga280_ads1259_setup_ads1259 ( unsigned char ch )
vitlog 0:f9ba28ab9f4c 33 /*Настройка АЦП*/
vitlog 0:f9ba28ab9f4c 34 {
vitlog 0:f9ba28ab9f4c 35 pga280_directCsBegin ( 4, ch );
vitlog 0:f9ba28ab9f4c 36 ads1259_resetDevice(ch); //костыльная функция
vitlog 1:533ce2102fcc 37 wait_ms(20); //пауза для выхода на режим работы
vitlog 0:f9ba28ab9f4c 38 ads1259_sendCommandDevice ( SDATAC_ADS1259 ); //установить чтение в постоянном режиме
vitlog 0:f9ba28ab9f4c 39 ads1259_writeOneRegisterDevice ( CONFIG0_ADS1259, 0x04 ); //0x04
vitlog 0:f9ba28ab9f4c 40 ads1259_writeOneRegisterDevice ( CONFIG1_ADS1259, 0x50 ); //0x50
vitlog 0:f9ba28ab9f4c 41 ads1259_writeOneRegisterDevice ( CONFIG2_ADS1259, 0x05 ); //0x03 400 400 сэмплов
vitlog 0:f9ba28ab9f4c 42 /*Настройка смещения так чтобы 7FFFFF - это нулевой уровень*/
vitlog 0:f9ba28ab9f4c 43 ads1259_writeOneRegisterDevice ( OFC0_ADS1259, 0x68 );//5D
vitlog 0:f9ba28ab9f4c 44 ads1259_writeOneRegisterDevice ( OFC1_ADS1259, 0x01 );//01
vitlog 0:f9ba28ab9f4c 45 ads1259_writeOneRegisterDevice ( OFC2_ADS1259, 0x00);
vitlog 0:f9ba28ab9f4c 46 /*Конец*/
vitlog 0:f9ba28ab9f4c 47 /*Настройка масштабирования 1 к 1*/
vitlog 0:f9ba28ab9f4c 48 ads1259_writeOneRegisterDevice ( FSC0_ADS1259, 0x00 );
vitlog 0:f9ba28ab9f4c 49 ads1259_writeOneRegisterDevice ( FSC1_ADS1259, 0x00 );
vitlog 0:f9ba28ab9f4c 50 ads1259_writeOneRegisterDevice ( FSC2_ADS1259, 0x40 );//0x40
vitlog 0:f9ba28ab9f4c 51 /*Конец*/
vitlog 0:f9ba28ab9f4c 52 pga280_directCsEnd ();
vitlog 0:f9ba28ab9f4c 53 }
vitlog 0:f9ba28ab9f4c 54
vitlog 0:f9ba28ab9f4c 55 unsigned char test_read_reg_ads1259 ( unsigned char ch )
vitlog 0:f9ba28ab9f4c 56 {
vitlog 0:f9ba28ab9f4c 57 unsigned char out_data;
vitlog 0:f9ba28ab9f4c 58
vitlog 0:f9ba28ab9f4c 59 pga280_directCsBegin ( 4, ch );
vitlog 0:f9ba28ab9f4c 60 out_data = ads1259_readOneRegisterDevice ( CONFIG0_ADS1259 );
vitlog 0:f9ba28ab9f4c 61 pga280_directCsEnd ();
vitlog 0:f9ba28ab9f4c 62
vitlog 0:f9ba28ab9f4c 63 return out_data;
vitlog 0:f9ba28ab9f4c 64 }
vitlog 0:f9ba28ab9f4c 65
vitlog 0:f9ba28ab9f4c 66 long ads1259_readData ( unsigned char ch )
vitlog 0:f9ba28ab9f4c 67 /*Эта функция работает, надо пофиксить основную*/
vitlog 0:f9ba28ab9f4c 68 {
vitlog 0:f9ba28ab9f4c 69 long data_out;
vitlog 0:f9ba28ab9f4c 70 unsigned char data[4];
vitlog 0:f9ba28ab9f4c 71 unsigned char data_ok;
vitlog 0:f9ba28ab9f4c 72 pga280_directCsBegin ( 4, ch );
vitlog 0:f9ba28ab9f4c 73 ads1259_sendCommandDevice ( SDATAC_ADS1259 ); // ?????????? ????? ?????? ?????? ? ?????????? ??????
vitlog 0:f9ba28ab9f4c 74 pga280_directCsEnd ();
vitlog 0:f9ba28ab9f4c 75
vitlog 0:f9ba28ab9f4c 76 ads1259_conversionON ( ch ); // ???????? ???
vitlog 0:f9ba28ab9f4c 77 //
vitlog 0:f9ba28ab9f4c 78 pga280_directCsBegin (4, ch );
vitlog 0:f9ba28ab9f4c 79 ads1259_sendCommandDevice ( RDATA_ADS1259 ); // ?????????? ??????? ??????? ???????? ?????? ? ?????????? ??????
vitlog 0:f9ba28ab9f4c 80 pga280_directCsEnd ();
vitlog 0:f9ba28ab9f4c 81
vitlog 0:f9ba28ab9f4c 82 do {
vitlog 0:f9ba28ab9f4c 83 if ( ads1259_readyDevice ( ch ) == true ) {
vitlog 0:f9ba28ab9f4c 84
vitlog 0:f9ba28ab9f4c 85
vitlog 0:f9ba28ab9f4c 86 pga280_directCsBegin ( 4, ch );
vitlog 0:f9ba28ab9f4c 87
vitlog 0:f9ba28ab9f4c 88 data[0] = SPI1MasterReadByte ();
vitlog 0:f9ba28ab9f4c 89 data[1] = SPI1MasterReadByte ();
vitlog 0:f9ba28ab9f4c 90 data[2] = SPI1MasterReadByte ();
vitlog 0:f9ba28ab9f4c 91 data[3] = 0;
vitlog 0:f9ba28ab9f4c 92
vitlog 0:f9ba28ab9f4c 93 pga280_directCsEnd ();
vitlog 0:f9ba28ab9f4c 94
vitlog 0:f9ba28ab9f4c 95 data_ok = true;
vitlog 0:f9ba28ab9f4c 96 break;
vitlog 0:f9ba28ab9f4c 97
vitlog 0:f9ba28ab9f4c 98 } else {
vitlog 0:f9ba28ab9f4c 99 data_ok = false;
vitlog 0:f9ba28ab9f4c 100 }
vitlog 0:f9ba28ab9f4c 101 } while ( 1 );
vitlog 0:f9ba28ab9f4c 102
vitlog 0:f9ba28ab9f4c 103 data_out = 0;
vitlog 0:f9ba28ab9f4c 104
vitlog 0:f9ba28ab9f4c 105 if ( data_ok ) {
vitlog 0:f9ba28ab9f4c 106 data_out += (data[0] & 0xFF) << 24;
vitlog 0:f9ba28ab9f4c 107 data_out += (data[1] & 0xFF) << 16;
vitlog 0:f9ba28ab9f4c 108 data_out += (data[2] & 0xFF) << 8;
vitlog 0:f9ba28ab9f4c 109 data_out += (data[3] & 0xFF);
vitlog 0:f9ba28ab9f4c 110 } else {
vitlog 0:f9ba28ab9f4c 111 data_out = 0xFFFFFFFF;
vitlog 0:f9ba28ab9f4c 112 }
vitlog 0:f9ba28ab9f4c 113
vitlog 0:f9ba28ab9f4c 114 ads1259_conversionOFF ( ch ); //
vitlog 0:f9ba28ab9f4c 115
vitlog 0:f9ba28ab9f4c 116 return data_out>>8;
vitlog 0:f9ba28ab9f4c 117 }
vitlog 0:f9ba28ab9f4c 118
vitlog 0:f9ba28ab9f4c 119 /* *****************************************************************************
vitlog 0:f9ba28ab9f4c 120 End of File
vitlog 0:f9ba28ab9f4c 121 */