From: Vladimir Garistov Date: Thu, 29 Aug 2024 18:17:40 +0000 (+0300) Subject: FIX: I don't actually remember what was wrong ¯\_(ツ)_/¯ X-Git-Url: https://kolegite.com/gitweb/?a=commitdiff_plain;h=a968a1a9f5150b549cdb168678e47668ac6e9981;p=vmks.git FIX: I don't actually remember what was wrong ¯\_(ツ)_/¯ --- diff --git a/Examples/SPI/SPI_digital_pot_MCP4261/SPI_digital_pot_MCP4261.ino b/Examples/SPI/SPI_digital_pot_MCP4261/SPI_digital_pot_MCP4261.ino index 6c09275..cbed6cc 100644 --- a/Examples/SPI/SPI_digital_pot_MCP4261/SPI_digital_pot_MCP4261.ino +++ b/Examples/SPI/SPI_digital_pot_MCP4261/SPI_digital_pot_MCP4261.ino @@ -1,14 +1,15 @@ #include #define INPUT_PIN A0 +#define CS_PIN 53 -#define WRITE_CMD 0x00 -#define INCR_CMD 0x01 -#define DECR_CMD 0x02 -#define READ_CMD 0x03 +#define WRITE_CMD ((uint16_t) 0x00) +#define INCR_CMD ((uint16_t) 0x01) +#define DECR_CMD ((uint16_t) 0x02) +#define READ_CMD ((uint16_t) 0x03) -#define WIPER0_ADDR 0x00 -#define WIPER1_ADDR 0x01 +#define WIPER0_ADDR ((uint16_t) 0x00) +#define WIPER1_ADDR ((uint16_t) 0x01) #define ADDR_OFFSET 12U #define CMD_OFFSET 10U @@ -24,11 +25,12 @@ void setup() void loop() { - SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0)); - SPI.transfer16( - WRITE_CMD << CMD_OFFSET | - WIPER0_ADDR << ADDR_OFFSET | - map(analogRead(INPUT_PIN), 0, 1023, 0, 256)); + uint16_t pot_val = map(analogRead(INPUT_PIN), 0, 1023, 0, 256); + SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0)); + digitalWrite(CS_PIN, LOW); + SPI.transfer16(WRITE_CMD << CMD_OFFSET | WIPER0_ADDR << ADDR_OFFSET | pot_val); + SPI.transfer16(WRITE_CMD << CMD_OFFSET | WIPER1_ADDR << ADDR_OFFSET | pot_val); + digitalWrite(CS_PIN, HIGH); SPI.endTransaction(); delay(5); }