• Main Page
  • Modules
  • Index
  • File List
  • Globals

hal/nrf24lu1p/hal_uart_sync.c

Go to the documentation of this file.
00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is confidential property of Nordic 
00004  * Semiconductor ASA.Terms and conditions of usage are described in detail 
00005  * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  *              
00011  * $LastChangedRevision: 133 $
00012  */
00013  
00018 #include "nrf24lu1p.h"
00019 #include <stdint.h>
00020 
00021 #include "hal_uart.h"
00022 
00023 
00024 #define BAUD_57K6   1015
00025 #define BAUD_38K4   1011
00026 #define BAUD_19K2    998
00027 #define BAUD_9K6     972
00028 
00029 void hal_uart_init(hal_uart_baudrate_t baud)
00030 {
00031   uint16_t temp;
00032 
00033   ES0 = 0;                      // Disable UART0 interrupt while initializing
00034   REN0 = 1;                     // Enable receiver
00035   SM0 = 0;                      // Mode 1..
00036   SM1 = 1;                      // ..8 bit variable baud rate
00037   PCON |= 0x80;                 // SMOD = 1
00038   WDCON |= 0x80;                // Select internal baud rate generator
00039 
00040   switch(baud)
00041   {
00042     case UART_BAUD_57K6:
00043       temp = BAUD_57K6;
00044       break;
00045     case UART_BAUD_38K4:
00046       temp = BAUD_38K4;
00047       break;
00048     case UART_BAUD_9K6:
00049       temp = BAUD_9K6;
00050       break;
00051     case UART_BAUD_19K2:
00052     default:
00053       temp = BAUD_19K2;
00054       break;
00055   }
00056 
00057   S0RELL = (uint8_t)temp;
00058   S0RELH = (uint8_t)(temp >> 8);
00059   P0ALT |= 0x06;                // Select alternate functions on P01 and P02
00060   P0EXP &= 0xf0;                // Select RxD on P01 and TxD on P02
00061   P0DIR |= 0x02;                // P01 (RxD) is input
00062   TI0 = 1;
00063 }
00064 
00065 void hal_uart_putchar(uint8_t ch)
00066 {
00067   while(TI0 == 0)
00068     ;
00069   TI0 = 0;
00070   S0BUF = ch;
00071 }
00072 
00073 uint8_t hal_uart_getchar(void)
00074 {
00075   while(RI0 == 0)
00076     ;
00077   RI0 = 0;
00078   return S0BUF;
00079 }
00080 
00081 static void hal_uart_putstring(char *s)
00082 {
00083   while(*s != 0)
00084   hal_uart_putchar(*s++);
00085 }

Generated on Fri Apr 20 2012 14:11:45 for nRFGo SDK by  doxygen 1.7.2