• AVR Freaks

Hot!Basic SPI Lib

New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2016/09/21 11:56:28
  • Location: 0
  • Status: offline
2019/10/25 16:05:28 (permalink)

Basic SPI Lib

Hi there, it's me again,
As before i noticed that there're too much issues using this protocol, so i made a basic (write and read) SPI harmony compatible library.
What you can do:
Write & Read (Useful for R&W external FLASH & EEPROM memories)
Write (Useful for communicating with modules that doesn't send )
FastRead (Useful for reading data above 10 Mhz)
void spi_write(SPI_MODULE_ID index, uint8_t data);
void spi_fast_read(SPI_MODULE_ID index, uint8_t *write_buffer, size_t write_num, uint8_t *read_buffer, uint32_t read_num);
void spi_write_read(SPI_MODULE_ID index, uint8_t *write_buffer, size_t write_num, uint8_t *read_buffer, uint32_t read_num);

How to use it:
Configure the harmony as always, select spi driver and configure it according to you needs (setup_spi.png)
Writing and Reading to/from external flash memory (IS25LP032D)
/*Enable Write*/
static const uint8_t Enable[] = { WREN };
// spi_write_read(SPI_ID_3,Enable,sizeof(Enable),NULL,0);
static const uint8_t datos[] = { PP, 0x00,0x00,0x00, 0xDA,0xED,0xAE,0xEA,WRDI };
// spi_write_read(SPI_ID_3,datos,sizeof(datos),NULL,0);
static const uint8_t leer[] = { NORD,0x00,0x00,0x00 };
static uint8_t rx_buffer[4];

Logic analyzer output: spi_flash.png
Mplabx simulation output: mplab_wr.png
Reading data @ 25 Mhz from external flash (IS25LP032D)
/*When use fast read you must control de CS line*/
spi_fast_read(SPI_ID_3,dato,sizeof(dato),rx_buffer, sizeof(rx_buffer));

Logic analyzer output: spi_fastread.png
Reading data from microSdcard (Sandisk 8Gb)
/*You must provide the FS*/
//saving data into array
spi_write(SPI_ID_3, rx_buffer[k]); } //writing data to display

Logic analyzer ouput: spi_sdcard.png
Due to the limit of 5 files you should download the library from my webpage.
So this is all for now any comments or suggestion please don't hesistate to contact me,
And as always do not forget to check out my website for more pic related projects: https://edx-twin3.org
Regards :1
post edited by _edx_ - 2019/10/26 17:08:33

Attached Image(s)

New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2016/09/21 11:56:28
  • Location: 0
  • Status: offline
Re: Basic SPI Lib 2019/10/25 16:08:52 (permalink)
I don't know why but won't let me put more than one URL, so anyways, also i've an I2C Library too (https://www.microchip.com/forums/m1078279.aspx)
post edited by _edx_ - 2019/10/27 14:18:47
Jump to:
© 2020 APG vNext Commercial Version 4.5