6 Spi
6 Spi
6 Spi
PIC18f452
MSSP MODULE MODES
The MSSP module can operate in one of two modes:
Serial Peripheral Interface (SPI)
Inter-Integrated Circuit (I2C)
Synchronized
Communications are “clocked”
3
SPI PERIPHERAL TYPES
Converters (ADC, DAC)
Memories (EEPROM, RAM’s,Flash)
Sensors (Temperature, Humidity, Pressure)
Real Time Clocks
Misc- Potentiometers, LCD controllers, UART’s, USB controller, CAN
controller,amplifiers
I/O Expanders etc……
NOTE: while
writing A7 is R/W
bit. Its not always 1 .
It can be 0, depends
upon slave device
attached
SPI MULTI BYTE BURST WRITE PROTOCOL
SPI SINGLE BYTE READ PROTOCOL
NOTE: while
reading A7 is R/W
bit. Its not always 0 .
It can be 1, depends
upon slave device
attached
SPI MULTI BYTE BURST READ PROTOCOL
Do proper
Load TRIS settings Load SSPBUF reg
SSPCON1 of SDI, SDO, with data to be
and SSPSTAT SS’ , SCK transmitted
pins
Then:
Read Opcode = 0b01000001 = 0x41
And Write Opcode = 0b01000000 = 0x40
HOW TO READ/WRITE TO I/O EXPANDER?
Steps to read data from a Steps to write data on a
specific memory location specific memory location
1. Send read OPCODE 1. Send write OPCODE
2. Send Register Address 2. Send Register address
3. In return, data at that 3. Send Data to be stored at
address would be thrown that memory location
out by IO expander. We
have to read that data
Code following scenario using Mikro C libraries to toggle GPA port continuously
of MCP23S17 constantly via SPI
void main() {
unsigned char val=0xaa;
while(1){
TRISC.TRISC0=0; //CS ,CE
TRISC.TRISC5=0;//SDO val=~val;