asd

Files at this revision

API Documentation at this revision

Comitter:
vitlog
Date:
Mon Jun 22 09:52:01 2020 +0000
Commit message:
Tozhe ne pomnyu

Changed in this revision

ad5422_arduino.cpp Show annotated file Show diff for this revision Revisions of this file
ad5422_arduino.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 9a5218876095 ad5422_arduino.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ad5422_arduino.cpp	Mon Jun 22 09:52:01 2020 +0000
@@ -0,0 +1,145 @@
+#include "ad5422_arduino.h"
+#include "PGA280.h"
+#include <math.h>
+#include "PerifConfig.h"
+#include <stdbool.h>
+
+
+void ad5422_resetDevice (  unsigned char adr )
+{
+    pga280_setAdress ( adr );
+    ADS1259_RESET = 0;
+    
+    wait_ms ( 1 );                            // ??? 1 Mhz 70
+    
+    ADS1259_RESET = 1;
+    pga280_resetAdress ();
+}
+
+void ad5422_powerDownDevice ( unsigned char adr )
+{
+    pga280_setAdress ( adr );
+    
+    ADS1259_RESET = 0;
+    
+    pga280_resetAdress ();
+}
+
+void ad5422_powerUpDevice ( unsigned char adr )
+{
+    pga280_setAdress ( adr );
+    
+    ADS1259_RESET = 1;
+    
+    pga280_resetAdress ();
+}
+
+char ad5422_readyDevice ( unsigned char ch )
+{
+    char tmp;
+    
+    pga280_setAdress ( ch );
+    
+    if ( CRDYA == 0 )
+        tmp = true;
+    else
+        tmp = false;
+    
+    pga280_resetAdress ();
+    
+    return tmp;
+}
+
+char ad5422_sendCommandDevice ( unsigned char reg, unsigned char high_byte, unsigned char low_byte, unsigned char adr )
+{
+    pga280_setAdress ( adr );
+    
+    CS = 0;    
+    SPI1MasterTransferByte ( reg );
+    SPI1MasterTransferByte( high_byte );
+    SPI1MasterTransferByte( low_byte );    
+    CS = 1;
+    
+   pga280_resetAdress ();
+    
+  return true;
+}
+
+uint32_t ad5422_readReg ( unsigned char reg, unsigned char adr )
+{    
+    union {
+    struct {
+        uint8_t
+        b0,
+        b1,
+        b2;
+    };
+    uint32_t data;
+    }read;
+  
+    pga280_setAdress ( adr );
+    CS = 0;
+  
+    SPI1MasterTransferByte( AD5422_READBACK );
+    SPI1MasterTransferByte( 0x00 );
+    SPI1MasterTransferByte( reg );
+
+    read.b0 = SPI1MasterReadByte();
+    read.b1 = SPI1MasterReadByte();
+    read.b2 = SPI1MasterReadByte();    
+    
+    CS = 1;
+    pga280_resetAdress ();
+    
+    return read.data;
+}
+
+unsigned int ad5422_setRegisters ( void )
+{
+    ad5422_sendCommandDevice ( AD5422_REG_RESET, 0x00, 0x01, AD5422_ADR );    
+    ad5422_sendCommandDevice ( AD5422_REG_CONTROL, 0x30, 0b00000001, AD5422_ADR );
+    return 1;
+}
+
+unsigned int ad5422_setRegistersChannal ( char channal )
+{
+    int i;
+    
+    for ( i = 0; i < channal; i++ )
+        ad5422_sendCommandDevice ( AD5422_REG_RESET, 0x00, 0x01, AD5422_ADR );
+    
+    wait_ms (1);
+    
+    for ( i = 0; i < channal; i++ )
+        ad5422_sendCommandDevice ( AD5422_REG_CONTROL, 0x00, 0x08, AD5422_ADR );
+    
+    wait_ms (1);
+    
+    for ( i = 0; i < channal; i++ )
+        ad5422_sendCommandDevice ( AD5422_REG_CONTROL, 0x30, 0x09, AD5422_ADR );
+    
+    wait_ms (1);
+    
+    return 1;
+}
+
+unsigned char ad5422_setVoltageChannal ( float voltage, char channal )
+{    
+    unsigned long tmp;
+    float v_ref = 5.2;
+    unsigned char gain = 2;
+    unsigned int value_output;
+    unsigned char value_output_high;
+    unsigned char value_output_low;
+    int i;
+    
+    tmp = ( voltage / ( v_ref * gain ) ) * 0xFFFF; 
+    value_output = ( v_ref * gain ) - tmp;
+    value_output_high = ( value_output >> 8 ) * 0xFF;
+    value_output_low = value_output * 0xFF;
+    
+    for ( i = 0; i < channal; i++ )
+        ad5422_sendCommandDevice ( AD5422_REG_DATA, value_output_high, value_output_low, AD5422_ADR );
+    
+    return (0);
+}
diff -r 000000000000 -r 9a5218876095 ad5422_arduino.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ad5422_arduino.h	Mon Jun 22 09:52:01 2020 +0000
@@ -0,0 +1,84 @@
+#ifndef _AD5422_ARDUINO_H    /* Guard against multiple inclusion */
+#define _AD5422_ARDUINO_H
+#include <stdint.h>
+/* Provide C++ Compatibility */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define AD5422_ADR                           0
+////////////////////////////////////////////// 
+// ************ Commands AD5422 *********** //
+//////////////////////////////////////////////
+    
+#define AD5422_NOP                        0x00
+#define AD5422_REG_DATA                   0x01
+#define AD5422_READBACK                   0x02
+#define AD5422_REG_CONTROL                0x55
+#define AD5422_REG_RESET                  0x56
+
+//////////////////////////////////////////////
+// *********** READ Registers ****************** //
+//////////////////////////////////////////////
+
+#define AD5422_STATUS_REGISTER            0x00
+#define AD5422_DATA_REGISTER              0x01
+#define AD5422_CONTROL_REGISTER           0x10
+
+    typedef union{
+        struct{
+            uint16_t
+            R0:1,
+            R1:1,
+            R2:1,
+            DCEN:1,
+            SREN:1,
+            SRSTEP:3,
+            SRCLOCK:4,
+            OUTEN:1,
+            REXT:1,
+            OVRRNG:1,
+            CLRSEL:1;            
+        };        
+        struct{
+            uint16_t 
+            L:8,
+            H:8;            
+        };
+    }AD5422_CONTROL_t;
+    extern AD5422_CONTROL_t AD5422_CONTROL;
+    
+    typedef union{
+        struct{
+            uint16_t
+            OverTemp:1,
+            SlewActive:1,
+            IoutFault:1,
+            :13;
+        };     
+        uint16_t w:16;
+        
+    }AD5422_STATUS_t;
+    extern AD5422_STATUS_t AD5422_STATUS;
+    
+    void ad5422_init ( void );
+    void ad5422_resetDevice (  unsigned char adr );
+    void ad5422_powerDownDevice ( unsigned char adr );
+    void ad5422_powerUpDevice ( unsigned char adr );
+    char ad5422_readyDevice ( unsigned char ch );
+    char ad5422_sendCommandDevice ( unsigned char reg, unsigned char high_byte, unsigned char low_byte, unsigned char adr );
+    uint32_t ad5422_readReg ( unsigned char reg, unsigned char adr );
+    unsigned int ad5422_setRegisters ( void );
+    unsigned int ad5422_setRegistersChannal ( char channal );
+    unsigned char ad5422_setVoltageChannal ( float voltage, char channal );
+
+    /* Provide C++ Compatibility */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _EXAMPLE_FILE_NAME_H */
+
+/* *****************************************************************************
+ End of File
+ */