예제 #1
0
파일: uart1.c 프로젝트: jtttl/STM8_Capture
/*******************************************************************************
 * 名称: UART1_SendByte
 * 功能: UART1发送一个字节
 * 形参: data -> 要发送的字节
 * 返回: 无
 * 说明: 无 
 ******************************************************************************/
void UART1_SendByte(u8 data)
{
	UART1_SendData8((unsigned char)data);
	
	/* 等待传输结束 */
	while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
}
예제 #2
0
//发送字节
void Send(uint8_t dat)
{
  //检查并等待发送寄存器是否为空
  while(( UART1_GetFlagStatus(UART1_FLAG_TXE)==RESET));
  //发送字节
  UART1_SendData8(dat);
}
예제 #3
0
void uart_send_str (unsigned char *SendData)
{
    uart_send=SendData;
    uart_send_length=uart_send_length_bk ;                    // Enable USCI_A0 TX interrupt
    UART1_SendData8(*uart_send);
    UART1_ITConfig(UART1_IT_TC,ENABLE  );
}
int main (void)
{
  clk_init();
  gpio_init();
  write_data_to_eeprom(default);
  read_data_from_eeprom();
  uart_init(baudrate);
  spi_init();
  setup();              // configure the cc2500 in required format.
                        /* Enable general interrupts */
  enableInterrupts();
  UART1_SendData8('R');
  UART1_SendData8('B');
  while (1)
  {
    while(command_mode)
    {
      if(a.data_complete)
      {
        handle_uart_request(uart_rcv_buff);
        write_data_to_eeprom(change);
        read_data_from_eeprom();
        a.data_complete = 0;
      }
//      else if(a.exit_command_mode)
//      {
//        break;
//      }
    }
    if(a.data_received_from_RF)
    {
        a.data_received_from_RF = 0;
        send_data_uart(Uart_send_buff);      
    }
    else if(a.data_received_from_UART)
    {
        a.data_received_from_UART = 0;
        send_data_rf(RF_send_buff);
    }
  }
}
예제 #5
0
__interrupt void UART1_TX_IRQHandler(void)
{
    if(UART1->SR&BIT6)
    {
        if(--uart_send_length>0)   UART1_SendData8(*(++uart_send));
        else
        {
            UART1_ITConfig(UART1_IT_TC,DISABLE);                       // Disable USCI_A0 TX interrupt
            uart_busy=0;
        }
    }
}
예제 #6
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
   /*High speed internal clock prescaler: 1*/
   CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

   /* UART1 configuration -------------------------------------------------------*/
   /* UART1 configured as follow:
          - Word Length = 8 Bits
          - 1 Stop Bit
          - No parity
          - BaudRate = 9600 baud
          - UART1 Clock enabled
          - Polarity Low
          - Phase Middle
          - Last Bit enabled
          - Receive and transmit enabled
   */
  UART1_DeInit();
  
  UART1_Init((uint32_t)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, 
              (UART1_SyncMode_TypeDef)(UART1_SYNCMODE_CLOCK_ENABLE | UART1_SYNCMODE_CPOL_LOW |UART1_SYNCMODE_CPHA_MIDDLE |UART1_SYNCMODE_LASTBIT_ENABLE),
              UART1_MODE_TXRX_ENABLE);
  UART1_Cmd(DISABLE);

  /* SPI configuration */
  SPI_DeInit();
  /* Initialize SPI in Slave mode  */
  SPI_Init(SPI_FIRSTBIT_LSB, SPI_BAUDRATEPRESCALER_2, SPI_MODE_SLAVE, SPI_CLOCKPOLARITY_LOW,
           SPI_CLOCKPHASE_1EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT,(uint8_t)0x07);

  /* Enable the UART1*/
  UART1_Cmd(ENABLE);
  
	Delay(0xFFF);
  
	/* Enable the SPI*/
  SPI_Cmd(ENABLE);
  
    while (NbrOfDataToRead--)
    {
        /* Wait until end of transmit */
        while (SPI_GetFlagStatus(SPI_FLAG_TXE)== RESET)
        {
        }
        /* Write one byte in the SPI Transmit Data Register */
        SPI_SendData(TxBuffer2[TxCounter]);
        /* Write one byte in the UART1 Transmit Data Register */
        UART1_SendData8(TxBuffer1[TxCounter++]);
        /* Wait until end of transmit */
        while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET)
        {
        }
        /* Wait the byte is entirely received by UART1 */
        while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET)
        {
        }
        /* Store the received byte in the RxBuffer1 */
        RxBuffer1[RxCounter] = UART1_ReceiveData8();
        /* Wait the byte is entirely received by SPI */
        while (SPI_GetFlagStatus(SPI_FLAG_RXNE) == RESET)
        {
        }
        /* Store the received byte in the RxBuffer2 */
        RxBuffer2[RxCounter++] = SPI_ReceiveData();
    }

    /* Check the received data with the sent ones */
    TransferStatus1 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1);
    /* TransferStatus = PASSED, if the data transmitted from UART1 and received by SPI are the same */
    /* TransferStatus = FAILED, if the data transmitted from UART1 and received by SPI are different */
    TransferStatus2 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2);
    /* TransferStatus = PASSED, if the data transmitted from SPI and received by UART1 are the same */
    /* TransferStatus = FAILED, if the data transmitted from SPI and received by UART11 are different */

    while (1);
}
예제 #7
0
/**
  * @brief  Send Data.
  * @param  Data: Data.
  * @retval None
  */
void UART1_SendByte(uint8_t Data)
{
    UART1_SendData8((uint8_t)Data);
    /* Loop until the end of transmission */
    while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
}
예제 #8
0
파일: main.c 프로젝트: msrLi/Robot
void Send(uint8_t dat)
{
  while(( UART1_GetFlagStatus(UART1_FLAG_TXE)==RESET));	
    UART1_SendData8(dat);	
}
예제 #9
0
파일: uart1.c 프로젝트: jtttl/STM8_Capture
/************************************************************************
 * 函数名:UART1_printf
 * 描述  :格式化输出,类似于C库中的printf,但这里没有用到C库
 * 输入  :-UARTx 串口通道,这里只用到了串口1,即UART1
 *		     -Data   要发送到串口的内容的指针
 *			   -...    其他参数
 * 输出  :无
 * 返回  :无 
 * 调用  :外部调用
 *         典型应用	 UART1_printf( "\r\n this is a demo \r\n" );
 *            		 UART1_printf(  "\r\n %d \r\n", i );
 *            		 UART1_printf(  "\r\n %s \r\n", j );
 ***************************************************************************/
void UART1_printf( uint8_t *Data,...)
{
	const char *s;
	int d;   
	char buf[16];
	va_list ap;
	va_start(ap, Data);
	
	while ( *Data != 0)     // 判断是否到达字符串结束符
	{				                          
		if ( *Data == 0x5c )  //'\'
		{									  
			switch ( *++Data )
			{
				case 'r':							          //回车符
					UART1_SendData8(0x0d);
					Data ++;
				break;
	
				case 'n':							          //换行符
					UART1_SendData8(0x0a);	
					Data ++;
				break;
	
				default:
					Data ++;
				break;
			}			 
		}
		else if ( *Data == '%')
		{					//
			switch ( *++Data )
			{				
				case 's':						//字符串
				s = va_arg(ap, const char *);
				for ( ; *s; s++) 
				{
					UART1_SendData8(*s);
					while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
				}
				Data++;
				break;
	
				case 'd':	//十进制
					d = va_arg(ap, int);
					itoa(d, buf, 10);
				for (s = buf; *s; s++) 
				{
					UART1_SendData8(*s);
					while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
				}
				Data++;
				break;
				
				default:
					Data++;
				break;
			}		 
		} /* end of else if */
		else UART1_SendData8(*Data++);
	
		while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
	}