in my application use nrf52 connect with max6675 thermo couple for read temperature
max6675 is configurable in spi mode.
in main.c
#define MAX6675_DEFAULT_CONFIG { \
.miso_pin = SPI_MISO_PIN, \ 09
.sck_pin = SPI_SCK_PIN, \ 10
.cs_pin = SPI_SS_PIN, \ 20
.spi_instance = NULL \
}
static void spi_config(max6675_config_t *max6675_config){
ret_code_t err_code;
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
NRF_LOG_DEBUG("spi config %d %d %d\n\r",max6675_config->miso_pin,max6675_config->sck_pin,max6675_config->cs_pin);
spi_config.sck_pin = max6675_config->sck_pin;
spi_config.mosi_pin = 0xFF; // not Used
spi_config.miso_pin = max6675_config->miso_pin;
spi_config.ss_pin = max6675_config->cs_pin; //0xFF; // max6675 need Conversion Time 220ms, so we set it external
// spi_config.frequency = NRF_DRV_SPI_FREQ_125K; // tCP = 100ns see MAX7219/MAX7221 Datasheet TIMING CHARACTERISTICS
spi_config.frequency = NRF_DRV_SPI_FREQ_8M; // tCP = 100ns see MAX7219/MAX7221 Datasheet TIMING CHARACTERISTICS
spi_config.mode = NRF_DRV_SPI_MODE_0; // SCK active high, sample on leading edge of clock.
spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
//err_code = nrf_drv_spi_init(&my_spi_0,&spi_config,NULL);
err_code = nrf_drv_spi_init(&my_spi_0,&spi_config,NULL,NULL);
APP_ERROR_CHECK(err_code);
}
void max6675_init(max6675_config_t const * const max6675_config) {
NRF_LOG_DEBUG("max6675_init %d\n\r",max6675_config->cs_pin);
nrf_gpio_cfg_output(max6675_config->cs_pin);
nrf_gpio_pin_set(max6675_config->cs_pin);
}
in 'nrf_drv_spi_init' not use 'spi_event_handler'
i prefer call for read in spi with appropriate timer_event_handler.
the application run well with sensorsim_measure, when change set in mode spi after not post notification on iPhone device
i have implemented un timer in
static void tcs_rate_meas_timeout_handler(void * p_context)
{
// Resolve 3 add
max6675_prepare(&max6675_config);
static uint32_t cnt = 0;
ret_code_t err_code;
uint16_t tcs_rate;
UNUSED_PARAMETER(p_context);
tcs_rate = max6675_readcelsius(&max6675_config); //(uint16_t)sensorsim_measure(&m_tcs_rate_sim_state, &m_tcs_rate_sim_cfg);
cnt++;
err_code = ble_hts_measurement_send(&m_hts, tcs_rate);
if ((err_code != NRF_SUCCESS) &&
(err_code != NRF_ERROR_INVALID_STATE) &&
(err_code != NRF_ERROR_RESOURCES) &&
(err_code != NRF_ERROR_BUSY) &&
(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
)
{
APP_ERROR_HANDLER(err_code);
}
// Disable RR Interval recording every third heart rate measurement.
// NOTE: An application will normally not do this. It is done here just for testing generation
// of messages without RR Interval measurements.
m_rr_interval_enabled = ((cnt % 3) != 0);
}
uint16_t max6675_readcelsius(max6675_config_t const * const max6675_config) {
ret_code_t err_code;
uint8_t outbuffer[2];
uint16_t temp;
//NRF_LOG_INFO("max6675_readcelsius\n\r");
//SEGGER_RTT_printf("max6675_prepare\n\r");
err_code = nrf_drv_spi_transfer(max6675_config->spi_instance,NULL,0,outbuffer,2);
APP_ERROR_CHECK(err_code);
nrf_gpio_pin_set(max6675_config->cs_pin);
//NRF_LOG_INFO("max6675_readcelsius out=%d %d\n\r",outbuffer[0],outbuffer[1]);
temp = ((uint16_t)outbuffer[0]<<8)|((uint16_t)outbuffer[1]);
temp = temp>>3;
temp = temp*25;
//NRF_LOG_DEBUG("max6675_readcelsius out=%d\n\r",temp);
return temp;
}
where I made mistakes ..... ????