| RTOS_MSPM0 1.1 ECE445M starter code

Files | Macros | Functions
SPI

Synchronous serial communication. More...

## Files
file | SPI.h
| 160 by 128 pixel LCD
file | SPI1.h
| Synchronous serial communication.

## Macros
#define | SDC_CS GPIOB
#define | SDC_CS_PIN (1<<0)
#define | SDC_CS_INDEX (PB0INDEX)
#define | SDC_CS_LOW() (SDC_CS->DOUTCLR31_0 = SDC_CS_PIN)
#define | SDC_CS_HIGH() (SDC_CS->DOUTSET31_0 = SDC_CS_PIN)
#define | TFT_CS GPIOB
#define | TFT_CS_PIN (1<<6)
#define | TFT_CS_INDEX (PB6INDEX)
#define | TFT_CS_LOW() (TFT_CS->DOUTCLR31_0 = TFT_CS_PIN)
#define | TFT_CS_HIGH() (TFT_CS->DOUTSET31_0 = TFT_CS_PIN)
#define | TFT_DC GPIOB
#define | TFT_DC_PIN (1<<16)
#define | TFT_DC_INDEX (PB16INDEX)
#define | TFT_DC_LOW() (TFT_DC->DOUTCLR31_0 = TFT_DC_PIN)
#define | TFT_DC_HIGH() (TFT_DC->DOUTSET31_0 = TFT_DC_PIN)
#define | TFT_RST GPIOB
#define | TFT_RST_PIN (1<<15)
#define | TFT_RST_INDEX (PB15INDEX)
#define | TFT_RST_LOW() (TFT_RST->DOUTCLR31_0 = TFT_RST_PIN)
#define | TFT_RST_HIGH() (TFT_RST->DOUTSET31_0 = TFT_RST_PIN)
#define | SDC_CS GPIOB
#define | SDC_CS_PIN (1<<0)
#define | SDC_CS_INDEX (PB0INDEX)
#define | SDC_CS_LOW() (SDC_CS->DOUTCLR31_0 = SDC_CS_PIN)
#define | SDC_CS_HIGH() (SDC_CS->DOUTSET31_0 = SDC_CS_PIN)
#define | TFT_CS GPIOB
#define | TFT_CS_PIN (1<<6)
#define | TFT_CS_INDEX (PB6INDEX)
#define | TFT_CS_LOW() (TFT_CS->DOUTCLR31_0 = TFT_CS_PIN)
#define | TFT_CS_HIGH() (TFT_CS->DOUTSET31_0 = TFT_CS_PIN)
#define | TFT_DC GPIOB
#define | TFT_DC_PIN (1<<16)
#define | TFT_DC_INDEX (PB16INDEX)
#define | TFT_DC_LOW() (TFT_DC->DOUTCLR31_0 = TFT_DC_PIN)
#define | TFT_DC_HIGH() (TFT_DC->DOUTSET31_0 = TFT_DC_PIN)
#define | TFT_RST GPIOB
#define | TFT_RST_PIN (1<<15)
#define | TFT_RST_INDEX (PB15INDEX)
#define | TFT_RST_LOW() (TFT_RST->DOUTCLR31_0 = TFT_RST_PIN)
#define | TFT_RST_HIGH() (TFT_RST->DOUTSET31_0 = TFT_RST_PIN)

## Functions
void | SPI_OutData (char data)
| Output data. More...
void | SPI_OutCommand (char command)
| Output command. More...
void | SPI1_Reset (void)
| Reset LCD. More...
void | CS_Init (void)
| SDC CS initialization. More...
void | SPI1_Init (void)
| initialize SPI1 More...
void | TFT_OutCommand (char command)
| Output command. More...
void | TFT_OutData (char data)
| Output data. More...

## Detailed Description

Synchronous serial communication.

Adafruit ST7735R pins
Pin | Connection | Description
--- | --- | ---
10 | +3.3 | Backlight
9 | PB7 | SPI1 MISO (used for SDC)
8 | PB9 | SPI1 SCLK clock out
7 | PB8 | SPI1 PICO data out
6 | PB6 | GPIO CS0=TFT_CS
5 | PB0 | CARD_CS (used for SDC)
4 | PB16 | Data/Command(GPIO), high for data, low for command
3 | PB15 | RESET, low to reset, (GPIO)
2 | +3.3 | VCC
1 | Gnd | ground

HiLetgo ST7735 TFT and SDC pins
signal | Pin | Connection
--- | --- | ---
LED- | 16 | TFT, to ground
LED+ | 15 | TFT, to +3.3 V
SD_CS | 14 | SDC, to PB0 chip select
MOSI | 13 | SDC, to PB8 MOSI
MISO | 12 | SDC, to PB7 MISO
SCK | 11 | SDC, to PB9 serial clock
CS | 10 | TFT, to PB6 SPI1 CS0
SCL | 9 | TFT, to PB9 SPI1 SCLK
SDA | 8 | TFT, to PB8 MOSI SPI1 PICO
A0 | 7 | TFT, to PB16 Data/Command, high for data, low for command
RESET | 6 | TFT, to PB15 reset (GPIO), low to reset
NC | 3,4,5 | not connected
VCC | 2 | to +3.3 V
GND | 1 | to ground

SPI-LCD pins
Pin | Function | Description
--- | --- | ---
PB9 | SPI1 SCLK <tdLCD SPI clock (SPI)
PB6 | GPIO CS | LCD SPI CS
PB0 | GPIO CS | SDC SPI CS
PB8 | SPI1 PICO | LCD SPI data (SPI)
PB7 | SPI1 POCI | SCD SPI data (SPI)
PB15 | GPIO | J2.17 LCD !RST =1 for run, =0 for reset
PB16 | GPIO | J4.31 LCD D/C RS =1 for data, =0 for command

## Function Documentation

## ◆ CS_Init()

void CS_Init | ( | void |  | ) |

SDC CS initialization.

SDC CS initialization -PB0 GPIO output -drive low to enable SDC -drive high to disable SDC

Parameters

  none |

Returns
  none

## ◆ SPI1_Init()

void SPI1_Init | ( | void |  | ) |

initialize SPI1

Initialize SPI1 for 8 MHz baud clock for both SDC and TFT using busy-wait synchronization. Calls Clock_Freq to get bus clock

- PB9 SPI1 SCLK
- PB6 SPI1 CS0
- PB8 SPI1 PICO
- PB15 GPIO !RST =1 for run, =0 for reset
- PB16 GPIO RS =1 for data, =0 for command

Note
  SPI0,SPI1 in power domain PD1 SysClk equals bus CPU clock

Parameters

  none |

Returns
  none

Initialize SPI1 for 8 MHz baud clock for both SDC and TFT using busy-wait synchronization. Calls Clock_Freq to get bus clock

- PB9 SPI1 SCLK
- PB6 SPI1 CS0
- PB8 SPI1 PICO
- PB15 GPIO !RST =1 for run, =0 for reset
- PA13 GPIO RS =1 for data, =0 for command

Note
  SPI0,SPI1 in power domain PD1 SysClk equals bus CPU clock

Parameters

  none |

Returns
  none

## ◆ SPI1_Reset()

void SPI1_Reset | ( | void |  | ) |

Reset LCD.

Reset LCD

1. drive RST high for 500ms
2. drive RST low for 500ms
3. drive RST high for 500ms

Parameters

  none |

Returns
  none

## ◆ SPI_OutCommand()

void SPI_OutCommand | ( | char | command | ) |

Output command.

Output 8-bit command to SPI port. RS=PA13=0 for command

Parameters

  command | is an 8-bit command to be transferred

Returns
  none

## ◆ SPI_OutData()

void SPI_OutData | ( | char | data | ) |

Output data.

Output 8-bit data to SPI port. RS=PA13=1 for data.

Parameters

  data | is an 8-bit data to be transferred

Returns
  none

## ◆ TFT_OutCommand()

void TFT_OutCommand | ( | char | command | ) |

Output command.

Output 8-bit command to SPI port. RS=PB16=0 for command.

Parameters

  data | is an 8-bit command to be transferred

Returns
  none

## ◆ TFT_OutData()

void TFT_OutData | ( | char | data | ) |

Output data.

Output 8-bit data to SPI port. RS=PB16=1 for data.

Parameters

  data | is an 8-bit data to be transferred

Returns
  none