PIC18, MPLAB X IDE, XC8, SPI, at45dbxx data flash
4MHz frequency 에서 spi clock으로 1MHz를 사용합니다.
- RC3 : CLK
- RC4 : SDI
- RC5 : SDO
- RA5 : CS
0. 참고 사항
1. HW 연결
2. 소스 설명
full 소스는 아래 github를 통해 확인하세요.
void init_spi( unsigned char sync_mode, unsigned char bus_mode, unsigned char smp_phase) { TRIS_SDI = 1; // SDI input TRIS_SDO = 0; // SD0 output SSPSTAT &= 0x3F; // power on state SSPCON1 = 0x00; // power on state SSPCON1 |= sync_mode; // select serial mode // 0000 = SPI Master mode, clock = FOSC/4 SSPSTAT |= smp_phase; // select data input sample phase
switch( bus_mode ) { case 0: // SPI bus mode 0,0 SSPSTATbits.CKE = 1; // data transmitted on rising edge break; case 2: // SPI bus mode 1,0 SSPSTATbits.CKE = 1; // data transmitted on falling edge SSPCON1bits.CKP = 1; // clock idle state high break; case 3: // SPI bus mode 1,1 SSPCON1bits.CKP = 1; // clock idle state high break; default: // default SPI bus mode 0,1 break; } switch( sync_mode ) { case 4: // slave mode w /SS enable TRIS_SCK = 1; // define clock pin as input TRIS_CS = 1; // define /SS1 pin as input break; case 5: // slave mode w/o /SS enable TRIS_SCK = 1; // define clock pin as input break; default: // master mode, define clock pin as output TRIS_SCK = 0; // define clock pin as output break; }
SSPCON1 |= 0x20; // enable synchronous serial port, 0b00100000 Enable serial port and configures SCK, SDO, SDI }
|
3. 소스
4. 결과
'PIC18' 카테고리의 다른 글
PIC18, MPLAB X IDE, XC8, CCP1, infrared (IR) (0) |
2018.09.16 |
PIC18, MPLAB X IDE, XC8, ADC, rotation_sensor (0) |
2018.09.14 |
PIC18, MPLAB X IDE, XC8, I2C, pcf8563 (0) |
2018.09.13 |
PIC18, MPLAB X IDE, XC8, PWM, buzzer (0) |
2018.09.13 |
PIC18, MPLAB X IDE, XC8, UART, rx_interrupt (0) |
2018.09.12 |