5.3.2.1 Application Logic

  1. To add and configure MPLAB Harmony components using the MCC, see SAM E70 Xplained Ultra Evaluation Kit.
  2. Add the following macros:
    #define RX_BUFFER_SIZE 1
    #define FRAC_BAUD_RATE 11000
    #define USART_SAMPLE_NUM 16 
    
    Figure 5-42. Defining the Macro for Fractional Baud Rate
  3. Add the following variables:
    uint16_t cd;
    uint8_t fp;  
    
  4. Add event handlers, see Step 1 in the Application Logic.
  5. Add the following code outside the main() function:
    void calculate_fractional_baud_value(const uint32_t baudrate, const uint32_t peripheral_clock,uint8_t sample_num)
    {
        uint32_t mul_ratio;
        mul_ratio = (uint64_t)((uint64_t)peripheral_clock*(uint64_t)1000)/(uint64_t)(baudrate*sample_num);
        cd = mul_ratio/1000;
        fp = ((mul_ratio - (cd*1000))*8)/1000;
    }
    
    void ext_usart_init(void)
    {
        calculate_fractional_baud_value(FRAC_BAUD_RATE,USART0_FrequencyGet(),USART_SAMPLE_NUM);
        
        USART0_REGS->US_CR = (US_CR_USART_RXDIS_Msk & US_CR_USART_TXDIS_Msk);
        
        USART0_REGS->US_BRGR = US_BRGR_CD(cd) | US_BRGR_CD(fp);
        
        USART0_REGS->US_CR = (US_CR_USART_TXEN_Msk | US_CR_USART_RXEN_Msk);
    } 
    
  6. In the following code examples, value of the fractional baud rate is calculated in the calculate_fractional_baud_value () function. In order to implement the fractional baud rate configuration, the register (US_CR, US_BRGR) operations are done in the ext_usart_init () function.
    Figure 5-43. Implementation of Fraction Baud Rate Configuration
  7. Add the remaining code, see Step 4 in the Application Logic.
    Figure 5-44. Host Side
    Figure 5-45. Client Side