AFE_NXP_Arduino 2.0.4 Analog Front-End (AFE) device operation sample code for Arduino

Loading...
Searching...
No Matches
SPI_for_AFE.cpp
Go to the documentation of this file.
1#include "AFE_NXP.h"
2
3 void SPI_for_AFE::txrx( uint8_t *data, int size )
4{
5// data[ 0 ] |= dev_ad ? 0x80 : 0x00;
6
7 SPI.beginTransaction( SPISettings( frequency, MSBFIRST, SPI_MODE1 ) );
8 digitalWrite( SS, LOW );
9 SPI.transfer( data, size );
10 digitalWrite( SS, HIGH );
11}
12
13 void SPI_for_AFE::write_r16( uint16_t reg )
14{
15 reg <<= 1;
16
17 uint8_t v[] = { (uint8_t)(reg >> 8), (uint8_t)(reg & 0xFF) };
18 txrx( v, sizeof( v ) );
19}
20
21 void SPI_for_AFE::write_r16( uint16_t reg, uint16_t val )
22{
23 reg <<= 1;
24
25 uint8_t v[] = { (uint8_t)(reg >> 8), (uint8_t)(reg & 0xFF), (uint8_t)(val >> 8), (uint8_t)val };
26 txrx( v, sizeof( v ) );
27}
28
29uint16_t SPI_for_AFE::read_r16( uint16_t reg )
30{
31 reg <<= 1;
32 reg |= 0x4000;
33
34 uint8_t v[ 4 ] = { (uint8_t)(reg >> 8), (uint8_t)(reg & 0xFF), 0xFF, 0xFF };
35 txrx( v, sizeof( v ) );
36
37 return get_data16( v + command_length );
38}
39
40 void SPI_for_AFE::write_r24( uint16_t reg, uint32_t val )
41{
42 reg <<= 1;
43
44 uint8_t v[] = { (uint8_t)(reg >> 8), (uint8_t)(reg & 0xFF), (uint8_t)(val >> 16), (uint8_t)(val >> 8), (uint8_t)val };
45 txrx( v, sizeof( v ) );
46}
47
48int32_t SPI_for_AFE::read_r24( uint16_t reg )
49{
50 reg <<= 1;
51 reg |= 0x4000;
52
53 uint8_t v[] = { (uint8_t)(reg >> 8), (uint8_t)(reg & 0xFF), 0xFF, 0xFF, 0xFF };
54 txrx( v, sizeof( v ) );
55
56 return get_data24( v + command_length );
57}
58
59 void SPI_for_AFE::burst( uint32_t *data, int length, int width )
60{
61 uint8_t v[ command_length + 3 * 16 ];
62 uint16_t reg = (0x2005 << 1) | 0x4000; // CMD_BURST_DATA
63
64 v[ 0 ] = (uint8_t)(reg >> 8);
65 v[ 1 ] = (uint8_t)(reg & 0xFF);
66
67 txrx( v, command_length + length * width );
68
69 for ( auto i = 0; i < length; i++ )
70 *data++ = get_data24( v + command_length + i * width );
71}
72
73 void SPI_for_AFE::spi_frequency( uint32_t f )
74{
75 frequency = f;
76}
77
78 void SPI_for_AFE::init( void )
79{
80 spi_frequency();
81
82 digitalWrite(SS, HIGH); // to set proper SPI_CS = HIGH before command/register access
83 delay( 1 );
84}
AFE_NXP.h
SPI_for_AFE::read_r24
virtual int32_t read_r24(uint16_t reg)
Definition SPI_for_AFE.cpp:48
SPI_for_AFE::txrx
virtual void txrx(uint8_t *data, int size)
Definition SPI_for_AFE.cpp:3
SPI_for_AFE::init
void init(void)
Definition SPI_for_AFE.cpp:78
SPI_for_AFE::write_r24
virtual void write_r24(uint16_t reg, uint32_t val)
Definition SPI_for_AFE.cpp:40
SPI_for_AFE::read_r16
virtual uint16_t read_r16(uint16_t reg)
Definition SPI_for_AFE.cpp:29
SPI_for_AFE::command_length
static constexpr int command_length
Definition SPI_for_AFE.h:102
SPI_for_AFE::burst
virtual void burst(uint32_t *data, int length, int width=3)
Definition SPI_for_AFE.cpp:59
SPI_for_AFE::frequency
uint32_t frequency
Definition SPI_for_AFE.h:83
SPI_for_AFE::get_data24
int32_t get_data24(uint8_t *vp)
Definition SPI_for_AFE.h:92
SPI_for_AFE::write_r16
virtual void write_r16(uint16_t reg)
Definition SPI_for_AFE.cpp:13
SPI_for_AFE::get_data16
int32_t get_data16(uint8_t *vp)
Definition SPI_for_AFE.h:87
SPI_for_AFE::spi_frequency
virtual void spi_frequency(uint32_t frequency=1 '000 '000)
Definition SPI_for_AFE.cpp:73