beautypg.com

Low level spi functions – Digilent 410-216P-KIT User Manual

Page 14

background image

chipKIT Basic I/O Shield Reference Manual

www.digilentinc.com

page 14 of 15

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.

Low Level SPI Functions


The following functions are used to write data to the display panel using the SPI controller.

/* ------------------------------------------------------------ */
/*** OledPutBuffer
**
**

Parameters:

**

cb

- number of bytes to send/receive

**

rgbTx

- pointer to the buffer to send

**
**

Return Value:

**

none

**
**

Errors:

**

none

**
**

Description:

**

Send the bytes specified in rgbTx to the slave.


*/

void
OledPutBuffer(int cb, BYTE * rgbTx)

{

int

ib;

BYTE bTmp;


/* Write/Read the data

*/

for (ib = 0; ib < cb; ib++) {

/* Wait for transmitter to be ready

*/

while (SPI2STATbits.SPITBE == 0);


/* Write the next transmit byte.

*/

SPI2BUF = *rgbTx++;


/* Wait for receive byte.

*/

while (SPI2STATbits.SPIRBF == 0);

bTmp = SPI2BUF;


}


}

/* ------------------------------------------------------------ */
/*** Spi2PutByte
**
**

Parameters:

**

bVal

- byte value to write

**
**

Return Value:

**

Returns byte read

**
**

Errors:

**

none

**
**

Description:

**

Write/Read a byte on SPI port 2