Hi,
I am new to embedded device development and I am wondering if I could get some help on SPI control from nrf51422/51822 chip with dev kit to AD9837 wave generator. I am using SS, SLK, and MOSI line and connected these lines according to standard definition of pins in the output. For the MCLK however, I am wondering what of the following 3 choices are the best/easiest to implement:
- Use a function generator to directly output a clock signal to AD9837
- Implement a timer on the microprocessor and output a clock signal to AD9837
- Get an external crystal
Then also there's the coding. I am not particularly familiar with this microprocessor, so I don't even know what could be wrong. Here's the main function with a small test of sending commands to generate a sinewave of 400Hz:
int main(void)
{
bsp_board_leds_init();
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_INFO("SPI example\r\n");
// configuration is done here; put constants here
// nrf_drv_spi_config_t spi_config = MSB_START | WOM_UEN | CPOL_H | CPHA_INI;
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
// change pins miso_pin to be not connected master in slave out pin not connected
spi_config.miso_pin = NRF_DRV_SPI_PIN_NOT_USED;
spi_config.ss_pin = SPI_SS_PIN;
spi_config.mosi_pin = SPI_MOSI_PIN;
spi_config.sck_pin = SPI_SCK_PIN;
spi_config.mode = NRF_DRV_SPI_MODE_0;
spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler));
int _freq = 400;
memset(m_tx_buf, 0, m_length);
spi_xfer_done = false;
// writeSPI(_length,_array,_CSdds, spiConf);
m_tx_buf[0] = 0x21;
m_tx_buf[1] = 0x00;
m_tx_buf[2] = 0x50;
m_tx_buf[3] = 0xC7;
m_tx_buf[4] = 0x40;
m_tx_buf[5] = 0x00;
m_tx_buf[6] = 0xC0;
m_tx_buf[7] = 0x00;
m_tx_buf[8] = 0x20;
m_tx_buf[9] = 0x00;
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, m_length, m_rx_buf, m_length)); // send
while (!spi_xfer_done)
{
__WFE();
}
bsp_board_led_invert(BSP_BOARD_LED_0);
nrf_delay_ms(100);
}
I have no idea how to proceed error-checking or debugging from here and would love some guidance and ideas please!
Thank you very much!