►Setting up the SPI port during startup.A51


For the upsd3334D, the SFR’s that set the functional aspects for the SPI port are P4SFS0 and P4SFS1. Your microcontroller will vary here, but the main idea is to setup the SPI pins so that you have an M0SI, MISO, SPICLK, and CS – These names correspond to “Micro OUT Slave IN”, “Micro IN Slave OUT”, “SPI CLocK”, and “Chip Select” respectively.


For my microcontroller, I set the port for the following settings, from within the STARTUP.A51 file (in assembler):

;------------------------------------------------------------;
; Program uPSD PORT-4 registers...                           ;
;                                                            ;
; P4SFS0 - sets the primary function of the pins             ;
; default is '0', which is GPIO pin                          ;
;                                                            ;
; 0 - buzzer output (PWM)   (set as alternate - 1)           ;
; 1 - SPIADDRESS SELECT 0 -|                                 ;
; 2 - SPIADDRESS SELECT 1  | These are used as 3-8           ;
;                            decoder for SPI device select   ;
; 3 - SPIADDRESS SELECT 2 -| (set as GPIO - 0)               ;
; 4 - spiclock               (set as alternate - 1)          ;
; 5 - MISO                   (set as alternate - 1)          ;
; 6 - MOSI                   (set as alternate - 1)          ;
; 7 - manual spi select line (set as GPIO - 0)               ;
;------------------------------------------------------------;
; P4SFS1 - sets the alternate function,                      ;
; if corresponding bit in P4SFS0 is set                      ;
;                                                            ;
; 0 - PCA0 Module 0, TCM0                (set as 0)          ;
; 1 - ignored, since P4SFS0 is 0 already (set as 0)          ;
; 2 - ignored, since P4SFS0 is 0 already (set as 0)          ;
; 3 - ignored, since P4SFS0 is 0 already (set as 0)          ;
; 4 - SPI Clock, SPICLK                  (set as 1)          ;
; 5 - SPI Receive, SPIRXD                (set as 1)          ;
; 6 - SPI Transmit, SPITXD               (set as 1)          ;
; 7 - ignored, since P4SFS0 is 0 already (set as 0)          ;
;                                                            ;
;------------------------------------------------------------;
	MOV     P4SFS0, #071H
	MOV     P4SFS1, #070H


Again, since your hardware platform will be different, you should setup your SPI port accordingly. The main idea here is to have an automated SPI port, and a manually controlled chip select – Don’t let the processor automatically control the CS line, since there are times when you will want it to stay either active or inactive, depending on what you are doing. My microcontroller has a feature that will automatically enable the CS line when the SPI clock runs, then automatically disable the CS line once the transmission is complete – Using this ability was a mistake, and so I disabled it, resorting to a manually controlled CS line.


Tutorial Index
Interface to Chan’s Library of functions SD Card Initialization
Target development platform Reading and Writing a single sector
Setting up the SPI port during startup.A51 Working with diskio.c
Global type definitions and variables Pulling it all together
Basic SPI function Index Page

Downloads

Comments

ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am
ArnoldDiant
Fri Apr 26 2024, 03:53 am
RodneyKnorb
Thu Apr 25 2024, 07:08 pm
Williamjef
Thu Apr 25 2024, 02:08 pm
SamuelSmise
Thu Apr 25 2024, 09:56 am
DustinErele
Thu Apr 25 2024, 08:44 am
ztaletpzca
Wed Apr 24 2024, 11:19 pm