View previous topic :: View next topic |
Author |
Message |
[email protected]
Joined: 13 Jun 2022 Posts: 4
|
SPI for SRAM read and write |
Posted: Mon Jun 13, 2022 1:54 pm |
|
|
Hello
Does someone would have an example of code to read and write data in a sram spi in blocks of data providing quantity of bytes, origin and destination of the data, example to read: spi_transfer_read(*TO, *FROM, BYTES_QTY);
to write
spi_transfer_write(*FROM, *TO, BYTES_QTY);
Regards |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Mon Jun 13, 2022 2:42 pm |
|
|
Probably one or two in the examples folder.... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 13, 2022 6:00 pm |
|
|
Driver for Microchip's 256K SPI Bus Low-Power Serial SRAM
Quote: | ..\picc\drivers\23k256.c
|
|
|
|
[email protected]
Joined: 13 Jun 2022 Posts: 4
|
SPI for SRAM read and write |
Posted: Tue Jun 14, 2022 6:19 am |
|
|
Thank you all, but it's not exactly what I'm looking for. I saw that CCS has a spi_transfer_read() and spi_transfer_write() function, but I just couldn't understand what the optional parameter [stream] is and what it's for, the example is not clear in this aspect, the same question when you want to use DMA. If you have any code examples it would be very helpful. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 14, 2022 10:00 am |
|
|
If you have two or more #use spi() statements, the stream parameter
allows you to give each statement a name.
If you wanted to do an SPI transfer with the parameters specified in your
first #use spi() , then you would specify the stream name for that
#use spi() when you call any of the CCS spi xfer functions.
If you wanted to do an SPI transfer with the parameters given in your 2nd
#use spi(), then you would specify the stream name for that one in your
spi xfer functions.
Stream names allow you to direct the compiler to use the #use spi()
statement that is appropriate for that transfer.
Say you have two SPI slave devices. They each have a different
maximum SCLK rate, which you specify in the two #use spi() statements.
You can ensure that the correct SCLK rate is used for each slave device
by entering the stream name for that device in your spi xfer function calls.
Also, if there are no stream names specified, the CCS compiler will use
the last #use spi() statement that it sees, linearly, scanning from top to
bottom of the source file. If you have two sequential #use spi()
statements at the start of your program (without stream names), the
compiler will ignore the first one and use the 2nd one for all spi xfer
function calls. You can get around this problem by positioning the
#use spi() statements above blocks of spi code in your .c modules.
But it's much easier to use streams. When you see the stream names
in your spi xfer code, you feel assured that the correct spi parameters
are being used for the specified spi slave device. |
|
|
[email protected]
Joined: 13 Jun 2022 Posts: 4
|
|
Posted: Tue Jun 14, 2022 12:29 pm |
|
|
Got it PCM programmer
Thanks a lot for the explanation about [stream].
But since I use only Spi SRAM's I´ll have only one #use spi() |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19544
|
|
Posted: Tue Jun 14, 2022 11:05 pm |
|
|
Which is why the stream is in square brackets, and 'optional'. Only needed
when you have more than one stream/#use.
It is essential when you do. Think about it. Two statements, which is
going to be used???. Answer give each a stream name, and add a stream
to the statements using these.
It is quite nice to use this even when it is not needed. If you are sensible
with your names (so for example make the name something like RAM256K,
adding this to the functions using the SPI, helps document 'where' the
commands are actually going. Can be a useful extra bit of data when going
back to the program in years time.... |
|
|
[email protected]
Joined: 13 Jun 2022 Posts: 4
|
|
Posted: Wed Jun 15, 2022 12:17 pm |
|
|
thank you very much, Ttelmah, i will do this |
|
|
|