when i try to configure spi1 i am getting error, so how can i configure different spi ?
when i try to configure spi1 i am getting error, so how can i configure different spi ?
Hi,
Can you explain which SDK you are using, how you configure your SPI and which error you get? Please elaborate.
Hi,
Can you explain which SDK you are using, how you configure your SPI and which error you get? Please elaborate.
/*
* DAC.c
*
* Created on: Nov 2, 2021
* Author: 91889
*/
#include "DAC.h"
#include "stdio.h"
//#include "main.h"
#include "nrf_drv_spi.h"
#include "nrf_gpio.h"
#include <string.h>
#define SPI_INSTANCE 0 /**< SPI instance index. */
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */
static volatile bool spi_xfer_done;
#define SPI_SS_PIN 31
#define SPI_MISO_PIN 30
#define SPI_MOSI_PIN 29
#define SPI_SCK_PIN 26
#define CS_Pin 5
#define VREF 2500
#define MULTIPLIER (65536 / VREF)
//extern SPI_HandleTypeDef hspi1;
void spi_event_handler(nrf_drv_spi_evt_t const *p_event,
void *p_context)
{
spi_xfer_done = true;
// NRF_LOG_INFO("Transfer completed.");
/* if (m_rx_buf[0] != 0)
{
NRF_LOG_INFO(" Received:");
NRF_LOG_HEXDUMP_INFO(m_rx_buf, strlen((const char *)m_rx_buf));
}*/
}
void Spi0_init(void)
{
nrf_drv_spi_config_t spi_config;
spi_config.ss_pin = SPI_SS_PIN;
spi_config.miso_pin = SPI_MISO_PIN;
spi_config.mosi_pin = SPI_MOSI_PIN;
spi_config.sck_pin = SPI_SCK_PIN;
spi_config.frequency = NRF_SPI_FREQ_4M;
spi_config.mode = NRF_SPI_MODE_0;
spi_config.bit_order = NRF_SPI_BIT_ORDER_MSB_FIRST;
APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));
}
void Dac_Input(uint8_t chanel, uint16_t value)
{
static uint8_t m_tx_buf[] = {0};
static uint8_t m_rx_buf[] = {0};
static const uint8_t m_length = sizeof(m_tx_buf);
float multipiler = (float)65536 / VREF;
uint8_t tx_Buffer;
uint16_t dac_Value;
if (value == 2500)
{
dac_Value = 65535;
}
else
{
dac_Value = (uint16_t)(value * multipiler);
}
nrf_gpio_cfg_output(CS_Pin);
nrf_gpio_pin_clear(CS_Pin);
//HAL_GPIO_WritePin(GPIOA, CS_Pin, GPIO_PIN_RESET);
if (chanel == channel_A)
{
memset(m_rx_buf, 0, m_length);
spi_xfer_done = false;
m_tx_buf[0] = 0x30;
//HAL_SPI_Transmit(&hspi1, &tx_Buffer, 1, 100);
nrf_drv_spi_transfer(&spi, m_tx_buf, m_length, m_rx_buf, NULL);
//HAL_Delay(50);
//power_down channel_B
// tx_Buffer = 0x41;
// HAL_SPI_Transmit(&hspi1, &tx_Buffer, 1, 100);
}
else
{
memset(m_rx_buf, 0, m_length);
spi_xfer_done = false;
m_tx_buf[0] = 0x31;
//HAL_SPI_Transmit(&hspi1, &tx_Buffer, 1, 100);
nrf_drv_spi_transfer(&spi, m_tx_buf, m_length, m_rx_buf, NULL);
//HAL_Delay(50);
//power_down channel_A
// tx_Buffer = 0x40;
// HAL_SPI_Transmit(&hspi1, &tx_Buffer, 1, 100);
}
memset(m_rx_buf, 0, m_length);
spi_xfer_done = false;
m_tx_buf[0] = (uint8_t)((dac_Value & 0xFF00) >> 8);
//HAL_SPI_Transmit(&hspi1, &tx_Buffer, 1, 100);
nrf_drv_spi_transfer(&spi, m_tx_buf, m_length, m_rx_buf, NULL);
memset(m_rx_buf, 0, m_length);
spi_xfer_done = false;
m_tx_buf[0] = (uint8_t)(dac_Value & 0x00FF);
//HAL_SPI_Transmit(&hspi1, &tx_Buffer, 1, 100);
nrf_drv_spi_transfer(&spi, m_tx_buf, m_length, m_rx_buf, NULL);
//HAL_GPIO_WritePin(GPIOA, CS_Pin, GPIO_PIN_SET);
nrf_gpio_pin_set(CS_Pin);
}when i configure spi like that clock was not generated at all
Hi,
I took the liberty to format your C code for improved readability.
You write that the clock was not generated. That means that no SPI transaction was started, so I expect an error has occured. I notice in your code that you ignore most return values. That is a very bad idea, and the first thing you should do is to improve your code so that you check all return values using APP_ERROR_CHECK (particularly the return values from nrf_drv_spi_transfer()). Are there any errors here? What else do you see from debugging?
code was hanged here
while (!nrf_spim_event_check(p_spim, NRF_SPIM_EVENT_END))
How to transfer a data in blocking mode?