| Electronic Components Datasheet Search |
|
SN8F5708 Datasheet(PDF) 150 Page - SONiX Technology Company |
|
|
|||||||||||||||||||||||||||||
SN8F5708 Datasheet(HTML) 150 Page - SONiX Technology Company |
|
150 / 204 page ![]() www.sonix.com.tw SN8F5708 Series Copyright © 2019, SONiX Technology Co., Ltd. SPI Datasheet Rev. 2.4 150 21.5 Sample Code The following sample code demonstrates how to perform SPI Master with interrupt. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 #define SpiMaster (1 << 4) //SPI = Master mode #define SpiSlave (1 << 4) //SPI = Slave mode #define SpiMode0 (0 << 2) //SCK idle low, data latch at rising edge #define SpiMode1 (1 << 2) //SCK idle low, data latch at falling edge #define SpiMode2 (2 << 2) //SCK idle high, data latch at falling edge #define SpiMode3 (3 << 2) //SCK idle high, data latch at rising edge #define SpiEn (1 << 6) //Enable SPI #define SpiSSNEn (0 << 5) //SSN pin function enable #define SpiSSNDis (1 << 5) //SSN pin function disable unsigned char u8SpiData = 0; // data buffer unsigned char u8TxCompleted = 0; void SpiMaster(void) { unsigned char u8RcvData = 0; //SCK & MOSI = output, MISO = input P1M |= 0x0A; //Enable Spi, Master mode, SSN pin disable, Fclk/128 //SCK idle low, data latch at falling edge SPCON = SpiEn | SpiMaster | SpiMode1 | SpiSSNDis | 0x82; //Enable Global/SPI interrupt IEN1 |= 0x02; IEN0 |= 0x80; //enable global interrupt while (1) { SPDAT = 0x55; while(!u8TxCompleted); // wait end of transmition u8TxCompleted = 0; // clear sw flag u8RcvData = u8SpiData; // receive 0x66 SPDAT = 0x99; while(!u8TxCompleted); // wait end of transmition u8TxCompleted = 0; // clear sw flag u8RcvData = u8SpiData; // receive 0xAA } } void SpiInterrupt(void) interrupt ISRSpi //0x4B { switch ( SPSTA ) // Clear SPI flag (SPIF) by reading { case 0x80: u8SpiData = SPDAT; u8TxCompleted = 1; break; case 0x10: // Mode Fault break; } } |
|
Link URL |
| Does ALLDATASHEET help your business so far? [ DONATE ] |
About Alldatasheet | Advertisement | Contact us | Privacy Policy | Link to Datasheet | Link Exchange | Manufacturer List All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |