THE INIT:
Code: Select all
spi_device_interface_config_t MY_VSPI_IFcfg = { 1, // uint8 command_bits simply T/R:: For a write, set the first bit to 0, and for a read, set this bit to 1.
15, // uint8_t address_bits; /// Default amount of bits in address phase (0-64), used when
//``SPI_TRANS_VARIABLE_ADDR`` is not used, otherwise ignored.
0, // uint8_t dummy_bits; /// Amount of dummy bits to insert between address and data phase
0, // uint8_t mode; /// SPI mode (0-3)
0, // uint8_t duty_cycle_pos; /// Duty cycle of positive clock, in 1/256th increments (128 = 50%/50% duty). Setting
// this to 0 (=not setting it) is equivalent to setting this to 128.
0, // uint8_t cs_ena_pretrans; /// Amount of SPI bit-cycles the cs should be activated before the transmission (0-16).
// This only works on half-duplex transactions.
0, // uint8_t cs_ena_posttrans; /// Amount of SPI bit-cycles the cs should stay active after the transmission (0-16)
.clock_speed_hz=SPI_MASTER_FREQ_8M/2, // 4MHz for now < Clock speed, divisors of 80MHz, in
.input_delay_ns =0, // int input_delay_ns; Maximum data valid time of slave. The time required between SCLK and MISO
.spics_io_num = GPIO_VPIN_CS0, //int spics_io_num; ///< CS GPIO pin for this device, or -1 if not used
.flags = SPI_DEVICE_HALFDUPLEX,// uint32_t flags; ///< Bitwise OR of SPI_DEVICE_* flags, one flag for searching
.queue_size = 4, //int queue_size; Transaction queue size. This sets how many transactions can be queued using
//spi_device_queue_trans but not yet finished using spi_device_get_trans_result) at the same time
.pre_cb = ADI_spi_pre_transfer_callback, // callback pointer transaction_cb_t - empty function
.post_cb = ADI_spi_post_transfer_callback // callback pointer transaction_cb_t - empty function
};
Ret_Val = spi_bus_initialize(My_VSPI, &My_VSPI_cfg , 2 ) ; // using DMA 2 ?
Ret_Val = spi_bus_add_device(My_VSPI, VSPI_Cfg_P, &SpiDevHandle );
DMA_ATTR uint32_t DumpBlock[512];// dump buffer, 2048 bytes
THE FUNCTION:
Code: Select all
Spi_StreamRead( const uint16_t Address, uint8_t *Data ,const uint8_t Count )
{ // misc local variable instantiation
spi_transaction_t trans = { // local stack copy of trans structure
0, // ,
1, // command bit to SPI, 1 is MISO I believe
.addr = Address,
0, Count*8, &DummyUserVal, // Total Length, Rcv Bits, &UserVar Tx only at this time and Rx data size
.tx_buffer = (void*) 0L, // Not Used}, // tx then rcv
.rx_buffer = (void*) DumpBlock // Returned Data }
};
// Set the correct command mode, only ctrl_reg has ascending, streaming is always I guess.
Ret_Val |= byte_Spi_Send( CONTROL_REG, ASCENDING4W );// ensure the device is in Ascending 4Wire Mode
Ret_Val |= spi_device_polling_transmit( SpiDevHandle, &trans );
memcpy( Data, DumpBlock, Count); //copy from DMA Block to calling pointer,
// other cleanup and return
}