/* This function both reads and writes data. For write operations, include data to be written as argument. For read ops, use dummy data as arg. Returned data is read byte val.  */
U8 chb_xfer_byte(U8 data)
/* This function both reads and writes data. For write operations, include data to be written as argument. For read ops, use dummy data as arg. Returned data is read byte val.  */
U8 chb_xfer_byte(U8 data)
{
    while ((SSP_SSP0SR & (SSP_SSP0SR_TNF_MASK | SSP_SSP0SR_BSY_MASK)) != SSP_SSP0SR_TNF_NOTFULL);
    SSP_SSP0DR = data;
    while ((SSP_SSP0SR & (SSP_SSP0SR_BSY_MASK | SSP_SSP0SR_RNE_MASK)) != SSP_SSP0SR_RNE_NOTEMPTY);
    return SSP_SSP0DR;
}