具有软件EUART和SPI的PIC18F45K80 QT1481

时间:2018-11-22 11:12:40

标签: c pic spi

因此,我成功地将0x0F发送到传感器并收到了响应0xF0。现在,我想做的是在软件EUART上看到我已将0x0F发送到传感器,并在收到传感器0xF0后收到一条消息。

这是我和我的朋友开发的代码,但是无法理解。我还附上了所见内容的屏幕截图。enter image description here  enter image description here

所以我尝试的主要代码是

while(1){
    char temp;
     __delay_us(100); // required previous to check DRDY (pag 26)
    while (PORTDbits.RD5 == 0) ; // wait until DRDY high
    QTA_SS_LAT_LOW ; // Put SS low
    __delay_us(10); // required if you are QT was in sleep mode (pag 22)
    WriteSPI(0x0F); // Send a byte - Transmit data
    __delay_us(2); // Wait for the byte to be shifted out
    QTA_SS_LAT_HIGH ; // Put SS high
    out_str("Sent 0x0F ",10,LSB);

    // Now transfer null command for getting the response
    __delay_us(100); // required previous to check DRDY (pag 26)
    while (PORTDbits.RD5 == 0) ; // wait until DRDY high
    QTA_SS_LAT_LOW ; // Put SS low
    __delay_us(10); // required if you are QT was in sleep mode
    temp = ReadSPI(); // Read a byte from the
    QTA_SS_LAT_HIGH ; // Stop transmitting data
    out_str("Received 0xF0 ",14,LSB);
}

还有out_str();函数:

void out_str(char * string, uint8_t len, char bit_order){
  uint8_t i = 0;
  for (i = 0; i< len; i++){
    out_char(string[i], bit_order);
  }
}

软件EUART应该从MOSI,MISO,DRDY和SS的专用引脚的RB5引脚和SPI中输出

SPI无需软件EUART就可以工作。enter image description here

对于使用ocklight的软件euart I。

0 个答案:

没有答案