Beispiel #1
0
void drv_rtc_set_time_date(rtc_t * set_time)
{
    uint8_t set_time_array[BCD_ARRAY_SIZE];
    drv_rtc_convert_struct_to_array(set_time, set_time_array, BCD_ARRAY_SIZE);

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

    // When the SPI port is available, set the address to write to.
    while (EUSCI_B_SPI_isBusy(EUSCI_B0_BASE))
    {
        ;
    }
    EUSCI_B_SPI_transmitData(EUSCI_B0_BASE, 0x80);

    uint8_t i;

    for ( i = 0; i < BCD_ARRAY_SIZE; i++)
    {
        // When the SPI port is available, write the data.
        while (EUSCI_B_SPI_isBusy(EUSCI_B0_BASE))
        {
            ;
        }
        EUSCI_B_SPI_transmitData(EUSCI_B0_BASE, set_time_array[i]);
    }

    // Deselect the RTC chip.
 //   bsp_pin_digital_write(&pins.rtc_cs, DISABLED);
}
Beispiel #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);
}
Beispiel #3
0
void drv_rtc_init(void)
{

    // Structure that holds all the SPI config info
    EUSCI_B_SPI_initMasterParam spi_b0_param =
    {
        EUSCI_B_SPI_CLOCKSOURCE_SMCLK,
        8000000,
        8000000,
        EUSCI_B_SPI_MSB_FIRST,
        EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT,
        EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW,
        EUSCI_B_SPI_3PIN
    };
    // Initalize and enable the SPI port.
    EUSCI_B_SPI_initMaster(EUSCI_B0_BASE, &spi_b0_param);
    EUSCI_B_SPI_enable(EUSCI_B0_BASE);

    // Enable the RTC chip's chip select.
  //  bsp_pin_digital_write(&pins.rtc_cs, ENABLED);

    // Wait for the SPI port to be available.
    while (EUSCI_B_SPI_isBusy(EUSCI_B0_BASE))
    {
        ;
    }
    // Send address to configure.
    EUSCI_B_SPI_transmitData(EUSCI_B0_BASE, 0x8E);

    // Wait for the SPI port to be available.
    while (EUSCI_B_SPI_isBusy(EUSCI_B0_BASE))
    {
        ;
    }
    // Config device to disable Osciallator and Battery SQ wave @1hz, temp
    // compensation, Alarms disabled.
    EUSCI_B_SPI_transmitData(EUSCI_B0_BASE, 0x60);

    // Deselect the RTC chip.
  //  bsp_pin_digital_write(&pins.rtc_cs, DISABLED);

    //delay(10);
}
Beispiel #4
0
void SPI_transmitData(uint32_t moduleInstance, uint_fast8_t transmitData)
{
    if (is_A_Module(moduleInstance))
    {
        EUSCI_A_SPI_transmitData(moduleInstance, transmitData);
    } else
    {
        EUSCI_B_SPI_transmitData(moduleInstance, transmitData);
    }

}