コード例 #1
0
// well the spi has to be setup. enough said
inline void configSPI1() {
  SPI1CON1 = SEC_PRESCAL_4_1 | // 4:1 prescale = 60MHz / 4 = 15MHz
             PRI_PRESCAL_1_1 |
             CLK_POL_ACTIVE_HIGH   | //clock active high (CKP = 0)
             SPI_CKE_ON          | //out changes inactive to active (CKE=0)
             SPI_MODE16_ON        | //16-bit mode
             MASTER_ENABLE_ON;     //master mode
  CONFIG_SDO1_TO_RP(RD4_RP);      //use RD4 for SDO
  CONFIG_RD4_AS_DIG_OUTPUT();   //Ensure that this is a digital output
  if(MY_ID == 0) {
    CONFIG_SCK1OUT_TO_RP(RD1_RP);   //use RD5 for SCLK
    CONFIG_RD1_AS_DIG_INPUT();   //Ensure that this is a digital input
  }
  else {
    CONFIG_SCK1OUT_TO_RP(RD5_RP);   //use RD5 for SCLK
    CONFIG_RD5_AS_DIG_INPUT();   //Ensure that this is a digital input
  }
  CONFIG_DAC();       //chip select for MCP41xxx
  DAC_DISABLE();             //disable the chip select
  SPI1STATbits.SPIEN = 1;  //enable SPI mode
}
コード例 #2
0
void configSPI1(void) {
  //spi clock = 40MHz/1*4 = 40MHz/4 = 10MHz
  SPI1CON1 = SEC_PRESCAL_1_1 |     //1:1 secondary prescale
             PRI_PRESCAL_4_1 |     //4:1 primary prescale
             CLK_POL_ACTIVE_HIGH | //clock active high (CKP = 0)
             SPI_CKE_ON          | //out changes active to inactive (CKE=1)
             SPI_MODE8_ON        | //8-bit mode
             MASTER_ENABLE_ON;     //master mode

  CONFIG_SDO1_TO_RP(RB8_RP);      //use RP6 for SDO
  //CONFIG_RB8_AS_DIG_PIN();   //Ensure that this is a digital pin
  CONFIG_SCK1OUT_TO_RP(RB7_RP);   //use RP7 for SCLK
  //CONFIG_RB7_AS_DIG_PIN();   //Ensure that this is a digital pin
  CONFIG_RB5_AS_DIG_OUTPUT();      //use RP5 for RST                   needs to be carefully removed
  //CONFIG_RB5_AS_DIG_PIN();   //Ensure that this is a digital pin
  RSTHIGH();
  

  CONFIG_SLAVE_ENABLE();     //slave select config
  //CONFIG_SLAVE_ORDY();       //output ready from slave
  SLAVE_DISABLE();           //disable slave
  SPI1STATbits.SPIEN = 1;    //enable SPI mode
}