CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

SPI for SRAM read and write

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ifox@ifox.com.br



Joined: 13 Jun 2022
Posts: 4

View user's profile Send private message

SPI for SRAM read and write
PostPosted: Mon Jun 13, 2022 1:54 pm     Reply with quote

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: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jun 13, 2022 2:42 pm     Reply with quote

Probably one or two in the examples folder....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 13, 2022 6:00 pm     Reply with quote

Driver for Microchip's 256K SPI Bus Low-Power Serial SRAM
Quote:
..\picc\drivers\23k256.c
ifox@ifox.com.br



Joined: 13 Jun 2022
Posts: 4

View user's profile Send private message

SPI for SRAM read and write
PostPosted: Tue Jun 14, 2022 6:19 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jun 14, 2022 10:00 am     Reply with quote

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.
ifox@ifox.com.br



Joined: 13 Jun 2022
Posts: 4

View user's profile Send private message

PostPosted: Tue Jun 14, 2022 12:29 pm     Reply with quote

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: 19510

View user's profile Send private message

PostPosted: Tue Jun 14, 2022 11:05 pm     Reply with quote

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....
ifox@ifox.com.br



Joined: 13 Jun 2022
Posts: 4

View user's profile Send private message

PostPosted: Wed Jun 15, 2022 12:17 pm     Reply with quote

thank you very much, Ttelmah, i will do this
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group