示例#1
0
文件: spi.c 项目: AlexTunea23/MPU6050
uint8_t SPI_receiveData(uint32_t moduleInstance)
{
    if (is_A_Module(moduleInstance))
    {
        return EUSCI_A_SPI_receiveData(moduleInstance);
    } else
    {
        return EUSCI_B_SPI_receiveData(moduleInstance);
    }

}
示例#2
0
rtc_t drv_rtc_read_time_date(void)
{

    // Create an array to hold the RTC data when read in from the chip.
    uint8_t TimeDate[7];      //second,minute,hour,null,day,month,year

    // Enable the RTC chip on the SPI bus.
  //  bsp_pin_digital_write(&pins.rtc_cs, ENABLED);

    // When the SPI port is available, select the starting address to read.
    while (EUSCI_B_SPI_isBusy(EUSCI_B0_BASE))
    {
        ;
    }
    EUSCI_B_SPI_transmitData(EUSCI_B0_BASE, 0x00);

    // Create an iterator.
    uint8_t i;

    // Loop through the RTC registers and read out the date and time.
    for ( i = 0; i <= 6; i++)
    {
        // When the SPI port is available, shift out don't care bits to shift
        // in the register we want to read.
        while (EUSCI_B_SPI_isBusy(EUSCI_B0_BASE))
        {
            ;
        }
        EUSCI_B_SPI_transmitData(EUSCI_B0_BASE, 0x00);

        // Once the transaction is complete retrieve the value shifted in.
        while (EUSCI_B_SPI_isBusy(EUSCI_B0_BASE))
        {
            ;
        }
        TimeDate[i] = EUSCI_B_SPI_receiveData(EUSCI_B0_BASE);
    }
    // Deselect the RTC chip.
 //   bsp_pin_digital_write(&pins.rtc_cs, DISABLED);

    // Create a RTC struct and stuff it with the converted bytes from the array.
    rtc_t current_time;
    drv_rtc_convert_array_to_struct(TimeDate, &current_time);

    // Return rtc struct
    return (current_time);
}