generated from LailaTheElf/rp2040_c
add read function
This commit is contained in:
parent
aac2f72fa3
commit
ee55984c93
@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.13)
|
|||||||
# note: this must happen before project()
|
# note: this must happen before project()
|
||||||
include(libs/pico-sdk/pico_sdk_init.cmake)
|
include(libs/pico-sdk/pico_sdk_init.cmake)
|
||||||
|
|
||||||
project(my_project)
|
project(temp_sensor)
|
||||||
|
|
||||||
# initialize the Raspberry Pi Pico SDK
|
# initialize the Raspberry Pi Pico SDK
|
||||||
pico_sdk_init()
|
pico_sdk_init()
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "hardware/spi.h"
|
#include "hardware/spi.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "max31856.h"
|
#include "max31856.h"
|
||||||
|
|
||||||
@ -45,3 +46,33 @@ int max31856_write8(max31856_t *max, uint8_t addr, uint8_t value)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t max31856_read8(max31856_t *max, uint8_t addr)
|
||||||
|
{
|
||||||
|
if (!(max->initilzed))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
const uint16_t buff_tx = (addr & 0x7F)<<8;
|
||||||
|
const uint8_t buff_rx[] = {0, 0};
|
||||||
|
gpio_put(max->pin_cs, 0);
|
||||||
|
spi_read_blocking(SPI_MAX31856, buff_tx, &buff_rx[0], 2);
|
||||||
|
gpio_put(max->pin_cs, 1);
|
||||||
|
|
||||||
|
return buff_rx[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t max31856_read16(max31856_t *max, uint8_t addr)
|
||||||
|
{
|
||||||
|
if (!(max->initilzed))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
const uint16_t buff_tx = (addr & 0x7F)<<8;
|
||||||
|
const uint8_t buff_rx[] = {0, 0, 0};
|
||||||
|
gpio_put(max->pin_cs, 0);
|
||||||
|
spi_read_blocking(SPI_MAX31856, buff_tx, &buff_rx[0], 3);
|
||||||
|
gpio_put(max->pin_cs, 1);
|
||||||
|
|
||||||
|
return buff_rx[1]<<8 | buff_rx[2];
|
||||||
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ typedef struct max31856_s {
|
|||||||
void max31856_init(max31856_t *max);
|
void max31856_init(max31856_t *max);
|
||||||
void max31856_deinit(max31856_t *max);
|
void max31856_deinit(max31856_t *max);
|
||||||
int max31856_write8(max31856_t *max, uint8_t addr, uint8_t value);
|
int max31856_write8(max31856_t *max, uint8_t addr, uint8_t value);
|
||||||
|
uint16_t max31856_read16(max31856_t *max, uint8_t addr);
|
||||||
|
|
||||||
#define MAX31856_REG_CR0 0x00
|
#define MAX31856_REG_CR0 0x00
|
||||||
#define MAX31856_REG_CR0_CMODE 0x80
|
#define MAX31856_REG_CR0_CMODE 0x80
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user