Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Chromatograph_Mobile Chromatograph_Mobile
PGA280.cpp
00001 #include "PGA280.h" 00002 #include <math.h> 00003 00004 /*Повторное объявление структур, из-за матюгов линковщика*/ 00005 __PGA280_GPIO_t PGA280_GPIO; 00006 __PGA280_MUX_GAIN_t PGA280_MUX_GAIN; 00007 __PGA280_SPI_MODE_t PGA280_SPI_MODE; 00008 __PGA280_BUF_TIMEOUT_t PGA280_BUF_TIMEOUT; 00009 __PGA280_ERROR_t PGA280_ERROR; 00010 adress_t adress; 00011 00012 void pga280_setAdress ( unsigned char adr ) 00013 /*Установить адрес микросемы на плате ТЭД-2 для работы*/ 00014 { 00015 adress.adr=adr; 00016 ADR0 = adress.adr0; 00017 ADR1 = adress.adr1; 00018 ADR2 = adress.adr2; 00019 } 00020 00021 void pga280_resetAdress ( void ) 00022 /*Сбросить адрес микросхемы на плате ТЭД-2*/ 00023 { 00024 ADR0 = 0; 00025 ADR1 = 0; 00026 ADR2 = 0; 00027 } 00028 00029 char pga280_sendCommandDevice ( unsigned char command, unsigned char adr ) 00030 /*Отправить устройству по адресу "adr" команду*/ 00031 { 00032 pga280_setAdress ( adr ); 00033 CS = 0; 00034 SPI1MasterTransferByte(command); 00035 CS = 1; 00036 //pga280_resetAdress (); 00037 00038 return 0xff; 00039 } 00040 00041 unsigned char pga280_readOneRegisterDevice ( unsigned char reg, unsigned char adr) 00042 /*Прочитать регистр "reg" с устройства по адресу "adr" 00043 Функция возвращает значение регистра*/ 00044 { 00045 unsigned char out_value = 0; 00046 00047 pga280_setAdress ( adr ); 00048 00049 CS = 0; 00050 SPI1MasterTransferByte ( READ_PGA280 | reg ); 00051 out_value = SPI1MasterTransferByte(0x00 ); 00052 CS = 1; 00053 //pga280_resetAdress (); 00054 00055 return out_value; 00056 } 00057 00058 void pga280_writeOneRegisterDevice (unsigned char reg, uint8_t data, unsigned char adr) 00059 /*Записать в регистр "reg" данные "data" в устройство по адресу "adr"*/ 00060 { 00061 pga280_setAdress ( adr ); 00062 00063 CS = 0; 00064 SPI1MasterTransferByte ( WRITE_PGA280 | reg ); 00065 SPI1MasterTransferByte ( data ); 00066 CS = 1; 00067 00068 //pga280_resetAdress (); 00069 } 00070 00071 void pga280_writeBufOneRegisterDevice (unsigned char reg, unsigned char data, unsigned char adr) 00072 { 00073 pga280_setAdress ( adr ); 00074 CS = 0; 00075 00076 SPI1MasterTransferByte ( WRITE_BUF_PGA280 | reg ); 00077 SPI1MasterTransferByte ( data ); 00078 00079 CS = 1; 00080 //pga280_resetAdress (); 00081 } 00082 00083 void pga280_directCS ( unsigned char ex_cs, unsigned char adr ) 00084 { 00085 pga280_setAdress ( adr ); 00086 CS = 0; 00087 00088 SPI1MasterTransferByte ( CS_DIRECT_PGA280 | ex_cs ); 00089 00090 CS = 1; 00091 //pga280_resetAdress (); 00092 } 00093 00094 void pga280_resetDevice ( unsigned char adr ) 00095 { 00096 pga280_writeOneRegisterDevice ( PGA280_RESET_ADR, 1, adr ); 00097 } 00098 00099 void pga280_setMUX ( unsigned char mux, unsigned char adr ) 00100 /*Выбрать канал АЦП "mux" на микросхеме по адресу "adr"*/ 00101 { 00102 PGA280_MUX_GAIN.MUX=mux; 00103 pga280_writeOneRegisterDevice ( PGA280_MUX_GAIN_ADR, PGA280_MUX_GAIN.w, adr ); 00104 } 00105 00106 void pga280_setGAIN ( unsigned char gain, unsigned char adr ) 00107 /*Установить коэффициент усиления "gain" на устройстве (pga280) 00108 по адресу "adr" (коэффициенты написаны в заголовочном файле) */ 00109 { 00110 PGA280_MUX_GAIN.GAIN=gain; 00111 pga280_writeOneRegisterDevice ( PGA280_MUX_GAIN_ADR, PGA280_MUX_GAIN.w, adr ); //запись в адрес регистра содержимого регистра 00112 } 00113 00114 void pga280_directCsBegin ( unsigned char exCS, unsigned char adr ) 00115 { 00116 pga280_setAdress ( adr ); 00117 00118 CS = 0; 00119 00120 SPI1MasterTransferByte ( CS_DIRECT_PGA280 | exCS ); 00121 } 00122 00123 void pga280_directCsEnd ( void ) 00124 { 00125 CS = 1; 00126 //RESET=0; 00127 //pga280_resetAdress (); 00128 } 00129 00130 void pga280_setGPIO ( unsigned char num, unsigned char adr ) 00131 /*Установить в лог. 1 GPIO вывод с номером "num" на устройстве по адресу "adr"*/ 00132 { 00133 PGA280_GPIO.GPIO |= 1 << num; 00134 pga280_writeOneRegisterDevice ( PGA280_GPIO_DATA_ADR, PGA280_GPIO.w, adr ); 00135 } 00136 00137 void pga280_resetGPIO ( unsigned char num, unsigned char adr ) 00138 /*Сбросить в лог. 0 GPIO вывод с номером "num" на устройстве по адресу "adr"*/ 00139 { 00140 PGA280_GPIO.GPIO &= ~(1 << num); 00141 pga280_writeOneRegisterDevice ( PGA280_GPIO_DATA_ADR, PGA280_GPIO.w, adr ); 00142 }
Generated on Thu Jul 14 2022 02:11:34 by
1.7.2