CANTram Framework 1.0.1
Dieses Framework ermöglicht die Nutzung der CANTram Hardware, einer Mikrocontroller basierten mdoularen Steuerung.
Loading...
Searching...
No Matches
MAX22531.h
Go to the documentation of this file.
1
11
12#ifndef MAX22531_H
13#define MAX22531_H
14
15#include <Arduino.h>
16#include <SPI.h>
17#include "MAX22531_registers.h"
18#include "SPIChip.h"
19#include "Debug.h"
20
21
22class MAX22531 : public SPIChip
23{
24 public:
26 uint8_t status;
27 uint16_t adc1;
28 uint16_t adc2;
29 uint16_t adc3;
30 uint16_t adc4;
31 uint16_t interrupt;
32 uint8_t crc;
33 bool filtered;
34 };
35
36 enum ERROR_CODES{
37 STATUS_OK = 0,
38 INVALID_CHANNEL = 10,
39 INVALID_REGISTER = 20,
40 NULL_POINTER = 30,
41
42 };
43
44 MAX22531(uint8_t csPin, uint8_t intPin);
45 MAX22531() = default;
46 ~MAX22531() = default;
47 bool begin();
48 uint8_t writeRegister(uint8_t address, uint16_t data);
49 uint16_t readRegister(uint8_t address, uint16_t* data = nullptr);
50 BurstResponse burstRead(bool filtered = true);
51 uint16_t readChannel(uint8_t channel, uint16_t* data = nullptr, bool filtered = true);
52 BurstResponse readAllChannels();
53 uint8_t HWreset();
54
55 private:
56
57 SPISettings _spiSettings = SPISettings(1000000, MSBFIRST, SPI_MODE0);
58 uint8_t resetPORFlag();
59 int8_t _intPin = -1;
60 bool useInt;
61 uint8_t calculateCRC(uint8_t *data, uint8_t length);
62 static constexpr uint8_t MAX_START_ATTEMPTS = 5;
63 static constexpr uint16_t START_RETRY_DELAY_MS = 1000;
64
65};
66
67#endif
Logging and debug macro definitions for CANTramCore.
Definition MAX22531.h:23
BurstResponse burstRead(bool filtered=true)
Performs a burst read of ADC channels and interrupt status from the MAX22531.
Definition MAX22531.cpp:134
BurstResponse readAllChannels()
Reads all filtered ADC channels and interrupt status from the MAX22531.
Definition MAX22531.cpp:188
uint16_t readRegister(uint8_t address, uint16_t *data=nullptr)
Reads a 16-bit value from a register on the MAX22531.
Definition MAX22531.cpp:96
MAX22531(uint8_t csPin, uint8_t intPin)
Constructs a MAX22531 object with specified chip select and interrupt pins.
Definition MAX22531.cpp:10
uint8_t writeRegister(uint8_t address, uint16_t data)
Writes a 16-bit value to a register on the MAX22531.
Definition MAX22531.cpp:66
bool begin()
Initializes the MAX22531 chip and confirms communication.
Definition MAX22531.cpp:17
uint8_t HWreset()
Performs a hardware reset of the MAX22531 via the CONTROL register.
Definition MAX22531.cpp:197
uint16_t readChannel(uint8_t channel, uint16_t *data=nullptr, bool filtered=true)
Reads a specific ADC channel from the MAX22531 and returns the 12-bit ADC value.
Definition MAX22531.cpp:168
Definition MAX22531.h:25