A combination of phase and polarity produces 4 standard modes for the clock in SPI:
Mode | CPOL/CKPL | CPHA/CKPH |
---|---|---|
0 | 0 | 0 |
1 | 0 | 1 |
2 | 1 | 0 |
3 | 1 | 1 |
It is important that the right phase and polarity are selected so that the slave and master both capture the bit at the correct clock transition.
Example using UCB0 module for MSp430Fr5969
P1SEL1 |= BIT6; // P1.6-> UCB0SIMO P1SEL1 |= BIT7 ; //P1.7-> UCB0SOMI P2SEL1 |= BIT2 ; //P2.2-> UCB0CLK * Set up the CS pin as output. * Set up the Clock speed and mode that match the salve speed and mode. (refer to the slave’s datasheet)
example using UCA0 module for MSP430FR5994
Config pins for UART operation P2.0 → UCA0TXD , P2.1→ UCA0RXD
P2SEL0 &= ~(BIT0 | BIT1);
P2SEL1 |= (BIT0 | BIT1);
Clock source 8 MHz and desired baud rate is 9600.
Step1: N = 8000000/9600 > 16
Step3: UCBRx = int (N/16) = 52 , OS16 = 1,
UCBRFx = int( ( (N/16) – INT(N/16) ) × 16) = 1
Step4: UCBRSx = 0x49 (by looking up the fractional part of N ( = N - INT(N) = 0.333333)
The I2C lives on UCBO on a MSP430 board.
Pull Low to send information.
Using clock stretching, the bus can be easily arbitrated: this stalls the bus by holding SCL low. This can be used to allow multiple nodes to be aware of when the bus is in use, or allow a device to stall the bus if more time is needed to handle data.