Skip to content

Commit

Permalink
Shorter interrupt locking of single SCK pulses
Browse files Browse the repository at this point in the history
Workaround for cases where BLE radio stack is used on the same core and higher priority interrupts are corrupting clock signal to the ADC - https://devzone.nordicsemi.com/f/nordic-q-a/113092/gpio-bit-banging-and-ble-radio-activity
  • Loading branch information
nobodyguy committed Jul 17, 2024
1 parent 25fb97e commit d3fc355
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions drivers/sensor/hx711/hx711.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@ static void hx711_gpio_callback(const struct device *dev, struct gpio_callback *
*/
static int hx711_cycle(struct hx711_data *data)
{
#ifdef CONFIG_HX711_DISABLE_INTERRUPTS_WHILE_POLLING
uint32_t key = irq_lock();
#endif
/* SCK set HIGH */
gpio_pin_set(data->sck_gpio, hx711_config.sck_pin, true);
k_busy_wait(1);

/* SCK set LOW */
gpio_pin_set(data->sck_gpio, hx711_config.sck_pin, false);
#ifdef CONFIG_HX711_DISABLE_INTERRUPTS_WHILE_POLLING
irq_unlock(key);
#endif
k_busy_wait(1);

/* Return DOUT pin state */
Expand Down Expand Up @@ -115,10 +121,7 @@ static int hx711_sample_fetch(const struct device *dev, enum sensor_channel chan
goto exit;
}

/* Clock data out. Optionally disable interrupts */
#ifdef CONFIG_HX711_DISABLE_INTERRUPTS_WHILE_POLLING
uint32_t key = irq_lock();
#endif
/* Clock data out. */
for (i = 0; i < 24; i++) {
count = count << 1;
if (hx711_cycle(data)) {
Expand All @@ -131,10 +134,6 @@ static int hx711_sample_fetch(const struct device *dev, enum sensor_channel chan
hx711_cycle(data);
}

#ifdef CONFIG_HX711_DISABLE_INTERRUPTS_WHILE_POLLING
irq_unlock(key);
#endif

count ^= 0x800000;
data->reading = count;

Expand Down

0 comments on commit d3fc355

Please # to comment.