Skip to content

Commit

Permalink
(mcp3008): Shift differential bit in the right direction
Browse files Browse the repository at this point in the history
  • Loading branch information
jcxldn committed Oct 7, 2023
1 parent 3a8d62a commit ad943cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/core/mcp3008/hardware/mcp3008_hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ uint16_t mcp3008_read_hardware(spi_dual_inst *inst, uint8_t channel, bool differ
output_buffer[0] = 0x01;

// Byte 2
// Bit 1, differential signal sleection
// Bit 1, differential signal selection
// Bits 2-4 channel select
// Rest of buffer ignored
output_buffer[1] = ((differential ? 0 : 1) >> 7 | channel << 4);
output_buffer[1] = ((differential ? 0 : 1) << 7 | channel << 4);

// temp
uint8_t input_buffer[BUF_LEN];
Expand All @@ -63,6 +63,7 @@ uint16_t mcp3008_read_hardware(spi_dual_inst *inst, uint8_t channel, bool differ
// Send the SPI command

gpio_put(inst->pinout->csn, 0);
__breakpoint();
spi_write_read_blocking(inst->spi_hw, output_buffer, input_buffer, BUF_LEN);
gpio_put(inst->pinout->csn, 1);

Expand Down
4 changes: 2 additions & 2 deletions src/core/mcp3008/pio/mcp3008_pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ uint16_t mcp3008_read_pio(spi_dual_inst *inst, uint8_t channel, bool differentia
output_buffer[0] = 0x01;

// Byte 2
// Bit 1, differential signal sleection
// Bit 1, differential signal selection
// Bits 2-4 channel select
// Rest of buffer ignored
output_buffer[1] = ((differential ? 0 : 1) >> 7 | channel << 4);
output_buffer[1] = ((differential ? 0 : 1) << 7 | channel << 4);

// temp
uint8_t input_buffer[BUF_LEN];
Expand Down

0 comments on commit ad943cd

Please sign in to comment.