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.
ad5422_arduino.cpp
00001 #include "ad5422_arduino.h" 00002 #include "PGA280.h" 00003 #include <math.h> 00004 #include "PerifConfig.h" 00005 #include <stdbool.h> 00006 00007 00008 void ad5422_resetDevice ( unsigned char adr ) 00009 { 00010 pga280_setAdress ( adr ); 00011 ADS1259_RESET = 0; 00012 00013 wait_ms ( 1 ); // ??? 1 Mhz 70 00014 00015 ADS1259_RESET = 1; 00016 pga280_resetAdress (); 00017 } 00018 00019 void ad5422_powerDownDevice ( unsigned char adr ) 00020 { 00021 pga280_setAdress ( adr ); 00022 00023 ADS1259_RESET = 0; 00024 00025 pga280_resetAdress (); 00026 } 00027 00028 void ad5422_powerUpDevice ( unsigned char adr ) 00029 { 00030 pga280_setAdress ( adr ); 00031 00032 ADS1259_RESET = 1; 00033 00034 pga280_resetAdress (); 00035 } 00036 00037 char ad5422_readyDevice ( unsigned char ch ) 00038 { 00039 char tmp; 00040 00041 pga280_setAdress ( ch ); 00042 00043 if ( CRDYA == 0 ) 00044 tmp = true; 00045 else 00046 tmp = false; 00047 00048 pga280_resetAdress (); 00049 00050 return tmp; 00051 } 00052 00053 char ad5422_sendCommandDevice ( unsigned char reg, unsigned char high_byte, unsigned char low_byte, unsigned char adr ) 00054 { 00055 pga280_setAdress ( adr ); 00056 00057 CS = 0; 00058 SPI1MasterTransferByte ( reg ); 00059 SPI1MasterTransferByte( high_byte ); 00060 SPI1MasterTransferByte( low_byte ); 00061 CS = 1; 00062 00063 pga280_resetAdress (); 00064 00065 return true; 00066 } 00067 00068 uint32_t ad5422_readReg ( unsigned char reg, unsigned char adr ) 00069 { 00070 union { 00071 struct { 00072 uint8_t 00073 b0, 00074 b1, 00075 b2; 00076 }; 00077 uint32_t data; 00078 }read; 00079 00080 pga280_setAdress ( adr ); 00081 CS = 0; 00082 00083 SPI1MasterTransferByte( AD5422_READBACK ); 00084 SPI1MasterTransferByte( 0x00 ); 00085 SPI1MasterTransferByte( reg ); 00086 00087 read.b0 = SPI1MasterReadByte(); 00088 read.b1 = SPI1MasterReadByte(); 00089 read.b2 = SPI1MasterReadByte(); 00090 00091 CS = 1; 00092 pga280_resetAdress (); 00093 00094 return read.data; 00095 } 00096 00097 unsigned int ad5422_setRegisters ( void ) 00098 { 00099 ad5422_sendCommandDevice ( AD5422_REG_RESET, 0x00, 0x01, AD5422_ADR ); 00100 ad5422_sendCommandDevice ( AD5422_REG_CONTROL, 0x30, 0b00000001, AD5422_ADR ); 00101 return 1; 00102 } 00103 00104 unsigned int ad5422_setRegistersChannal ( char channal ) 00105 { 00106 int i; 00107 00108 for ( i = 0; i < channal; i++ ) 00109 ad5422_sendCommandDevice ( AD5422_REG_RESET, 0x00, 0x01, AD5422_ADR ); 00110 00111 wait_ms (1); 00112 00113 for ( i = 0; i < channal; i++ ) 00114 ad5422_sendCommandDevice ( AD5422_REG_CONTROL, 0x00, 0x08, AD5422_ADR ); 00115 00116 wait_ms (1); 00117 00118 for ( i = 0; i < channal; i++ ) 00119 ad5422_sendCommandDevice ( AD5422_REG_CONTROL, 0x30, 0x09, AD5422_ADR ); 00120 00121 wait_ms (1); 00122 00123 return 1; 00124 } 00125 00126 unsigned char ad5422_setVoltageChannal ( float voltage, char channal ) 00127 { 00128 unsigned long tmp; 00129 float v_ref = 5.2; 00130 unsigned char gain = 2; 00131 unsigned int value_output; 00132 unsigned char value_output_high; 00133 unsigned char value_output_low; 00134 int i; 00135 00136 tmp = ( voltage / ( v_ref * gain ) ) * 0xFFFF; 00137 value_output = ( v_ref * gain ) - tmp; 00138 value_output_high = ( value_output >> 8 ) * 0xFF; 00139 value_output_low = value_output * 0xFF; 00140 00141 for ( i = 0; i < channal; i++ ) 00142 ad5422_sendCommandDevice ( AD5422_REG_DATA, value_output_high, value_output_low, AD5422_ADR ); 00143 00144 return (0); 00145 }
Generated on Fri Jul 15 2022 07:00:34 by
1.7.2