This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

[SD Card] Sharing SPI pins sdcard

Hi,

I'm trying to use the nrf52832 with a sdcard application in SDK_13. I based my code on the example provided and managed to get the sd card working without any problems.

However I am now trying to get the another SPI slave working sharing the MOSI, MISO and CLK lines of the SD card without any success. I already manage the chip select pins manually before every call to the sdcard and the other spi slave however it still does not work.

I commented out the APP_ERROR_CHECK since the spi might already be initialized err_code = nrf_drv_spi_init(&m_spi, &spi_cfg, spi_handler, NULL); /*APP_ERROR_CHECK(err_code);*/

Does anyone have any idea on how to make it work? Is it possible using the SDK?

Here is an excerpt of the code which contains the main steps used:

nrf_gpio_cfg_output(cs_sdcard);
nrf_gpio_pin_write(cs_sdcard, HIGH);

nrf_gpio_cfg_output(cs_slave2);
nrf_gpio_pin_write(cs_slave2, HIGH);

/* Desired sector size and pins to configure */
m_block_dev_sdc.sdc_bdev_config.block_size = SDC_SECTOR_SIZE;
m_block_dev_sdc.sdc_bdev_config.sdc_config.mosi_pin = SPI_MOSI;
m_block_dev_sdc.sdc_bdev_config.sdc_config.miso_pin = SPI_MISO;
m_block_dev_sdc.sdc_bdev_config.sdc_config.sck_pin = SPI_SCLK;


/* Initialize SDcard block device work structure */
m_block_dev_sdc.p_work = &this->m_block_dev_sdc_work;
m_block_dev_sdc.block_dev.p_ops = (const nrf_block_dev_s::nrf_block_dev_ops_s*)&nrf_block_device_sdc_ops;

/* Initialize structure to registers a drive */
drive.config.p_block_device = &m_block_dev_sdc.block_dev;
drive.config.wait_func = NULL;
drive.last_result = NRF_BLOCK_DEV_RESULT_SUCCESS;
drive.state = STA_NOINIT;
drive.busy = false;

/* Registers a drive */
diskio_blockdev_register(&drive, NUMBER_OF_DRIVES);

/* Pointer to the file system object to be registered */
static FATFS filesys;

FRESULT mount_result;

nrf_gpio_pin_write(cs_sdcard, LOW);

/* Mounting volume */
mount_result = f_mount(&filesys, DEFAULT_DRIVE, MOUNT_IMMEDIATELY_OPT);

nrf_gpio_pin_write(cs_sdcard, HIGH);

nrf_gpio_pin_write(cs_sdcard, LOW);

/* Creating a partition */
f_fdisk(PHYSICAL_DRIVE, plist, &work);

/* Creating FAT32 file system */
create_fs_result = f_mkfs(DEFAULT_DRIVE, FM_FAT32, DEFAULT_ALLOCATION_UNIT_SIZE, work, sizeof(work));

nrf_gpio_pin_write(cs_sdcard, HIGH);

nrf_gpio_pin_write(cs_sdcard, LOW);

create_sign_result = f_open(&file1, FILE_SIGN_NAME, FA_CREATE_ALWAYS);

nrf_gpio_pin_write(cs_sdcard, HIGH);

/* This does not work */
nrf_gpio_pin_write(cs_slave2, LOW);

nrf_drv_spi_transfer(&spi_instance, register, size_register, NULL, 0);

nrf_gpio_pin_write(cs_slave2, HIGH);

Thanks

Edit: Added excerpt of code

Parents
  • I may have misunderstood a thing or two. First, it shouldn't be any issues with having several slaves connected to the same SPI pins as long as you use the Slave Select pins correctly. Furthermore, unless you have to change frequency, modes, or bit order you should not re-initialize the SPI either.

    Do you mind uploading your code? You can edit your original question and attach a .c file there.

Reply
  • I may have misunderstood a thing or two. First, it shouldn't be any issues with having several slaves connected to the same SPI pins as long as you use the Slave Select pins correctly. Furthermore, unless you have to change frequency, modes, or bit order you should not re-initialize the SPI either.

    Do you mind uploading your code? You can edit your original question and attach a .c file there.

Children
No Data
Related