コード例 #1
0
/*****************************************************************************
 Send (unsigned char)tx_uint as decimal number with leading zeros out via the UART
 ****************************************************************************/
void UART_send_uchar(void) {
    tx_uint = tx_uint & 0xff;
    
    tx_value = 0;
    while (tx_uint >= 100) {
        tx_uint -= 100;
        ++tx_value;
    }
    tx_value += '0';
    UART_send();

    tx_value = 0;
    while (tx_uint >= 10) {
        tx_uint -= 10;
        ++tx_value;
    }
    tx_value += '0';
    UART_send();

    tx_value = tx_uint + '0';
    UART_send();

    tx_value = '\n';
    UART_send();
}
コード例 #2
0
void METER_ISR ( void )
{
	uint8_t data[3];

	// Interrupt DO fired
	if (DOIFG & DO_PIN) {
		// we need access to the UART interrupts
		DOIE &= ~DO_PIN;
		enable_interrupts();

		// read power
		UART_clear();
		UART_send(METER_read_power, sizeof(METER_read_power));
		UART_recv(data, sizeof(data), '\0', USCI_BLOCKING);

		// convert the byte array to a 32bit value
		metered_power = (uint32_t)data[0];
		metered_power += ((uint32_t)data[1]<<8);
		metered_power += ((uint32_t)data[2]<<16);

		// clear our pending interrupt
		DOIFG &= ~DO_PIN;
		DOIE |= DO_PIN;

		// clear the interrupt from the power meter
		UART_send(METER_clear_drdy, sizeof(METER_clear_drdy));
	}
}
コード例 #3
0
ファイル: hal_assert.c プロジェクト: dcesiel/eecs373final
/*-------------------------------------------------------------------------*//**
 *
 */
void HAL_assert_fail
(
    const uint8_t * file_name,
    uint32_t line_no
)
{
    const uint8_t fail_msg[] = "\r\nHAL_ASSERT: ";
    const uint8_t line_msg[] = ", line ";
    uint8_t line_nb_msg[256];
    uint32_t msg_length;
    
    g_test_error = ASSERTION_ERROR_CODE;
    
    UART_send( &g_ext_uart,	fail_msg, sizeof(fail_msg) );
    
    for ( msg_length = 0; (msg_length < MAX_PATH_FILE_NAME) && (file[msg_length] != 0); msg_length++ )
    {
        ;
    }

    UART_send( &g_ext_uart,	(const uint8_t *)file, msg_length );
    UART_send( &g_ext_uart, line_msg, sizeof(line_msg) );

    msg_length = hal_assert_int_2_text( line_nb_msg, sizeof(line_nb_msg), line_no );
    
    UART_send( &g_ext_uart, line_nb_msg, msg_length );
}
コード例 #4
0
ファイル: Motor_driver.c プロジェクト: PhamVanNhi/ECE5770
void Motor_run()
{
  if(MPI_check_available(MOTOR_DRIVER_PID) == true)
    {
      MPI_get_message(MOTOR_DRIVER_PID, &incomingPID, &cmdSize, incomingMsg);

      if(cmdSize == sizeof(int))
	{
	  OS_memcpy(&incomingCmd, incomingMsg, cmdSize);

	  switch(incomingCmd)
	    {
	    case C_DRIVE_FORWARD:
	      UART_send("drive forward\r\n", CONSOLE_BASE);
	      driveForward();

	      break;

	    case C_DRIVE_REVERSE:
	      UART_send("drive reverse\r\n", CONSOLE_BASE);
	      driveReverse();

	      break;

	    case C_DRIVE_LEFT:
	      UART_send("drive left\r\n", CONSOLE_BASE);
	      driveLeft();
	      
	      break;

	    case C_DRIVE_RIGHT:
	      UART_send("drive right\r\n", CONSOLE_BASE);
	      driveRight();

	      break;

	    case C_DRIVE_HALT:
	      UART_send("drive halt\r\n", CONSOLE_BASE);
	      driveHalt();

	      break;

	    }

	}

    }

}
コード例 #5
0
ファイル: glove.c プロジェクト: TimofonicJunkRoom/Oldies
int glove_init (void) {
  UART_send (0x41);
  if (UART_receive()!=0x55) 
    return 0;
  else
    return 1;
}
コード例 #6
0
ファイル: zigbee.c プロジェクト: ikerexxe/BroadCar
/**
* @brief Función para se usa para reenviar el mensaje que se ha recibido
* mediante zigbee.
*
* @return -
*
* Permite reenviar el mensaje recibido mediante zigbee siempre y cuando
* haya saltos disponibles.
*/
void reenviar_mensaje(MENSAJEClass mensaje){
	//Si se puede reenviamos el mensaje
	if(mensaje.ttl > 0){
		mensaje.ttl--;
		formatear_mensaje(mensaje);
		UART_send(gs_i_puerto_zigbee, gs_ba_envio, &gs_i_tamano);
	}
}
コード例 #7
0
/**
 * A simple task that will activate when there is data in the queue and send
 * this to the UART.
 */
static void vSerialTxTask(void *pvParameters)
{
    (void) pvParameters;
    char cOutChar = 0;
    for(;;){
        if(xQueueReceive(xTxQueue, &cOutChar, 10000) == pdPASS){
            UART_send(&g_uart, (const uint8_t *) &cOutChar, 1);
        }
    }
}
コード例 #8
0
int main()
{
	UART_init(9600); // 把串口波特率配置为9600
	
	while(1)
	{
		delay();
		UART_send("www.rationMCU.com", 17);//串口发送字符串数组
		UART_send_byte('\n'); //串口发送换行符字节
	}
}
コード例 #9
0
ファイル: main.c プロジェクト: thehappycheese/hk310-expansion
/*****************************************************************************
 main()
 
 No introduction needed ... 
 ****************************************************************************/
void main(void) {
    Init_hardware();
    Init_UART();
    
    while (1) {
        uint8_t b;
        b = UART_read_byte();
        b = filter(b);
        UART_send(b);
    }
}
コード例 #10
0
void METER_begin ( )
{
	// configure interrupt DO on p1.4
	DOSEL &= ~DO_PIN;
	DOSEL2 &= ~DO_PIN;
	DODIR &= ~DO_PIN;
	DOIFG &= ~DO_PIN;
	DOIE |= DO_PIN;

	// Begin continuous mode conversions
	UART_send(METER_begin_conv, sizeof(METER_begin_conv));
}
コード例 #11
0
ファイル: zigbee.c プロジェクト: ikerexxe/BroadCar
/**
 * @brief  Función para enviar un mensaje mediante zigbee.
 *
 * @return    -
 *
 * Recoge los datos del sensor, le da un formato adecuado para enviar
 * mediante zigbee y lo envía.
*/
void ZIGBEE_enviar_mensaje(SENSORClass sensor){
	MENSAJEClass mensaje;

	mensaje = insertar_tipo_mensaje(mensaje, sensor.tipo);
	mensaje.id = g_i_mi_id;
	mensaje.hora = sensor.hora;
	mensaje.posicion = sensor.posicion;
	mensaje.ttl = 3;
	mensaje = insertar_info_mensaje(sensor, mensaje);

	formatear_mensaje(mensaje);
	UART_send(gs_i_puerto_zigbee, gs_ba_envio, &gs_i_tamano);
}
コード例 #12
0
void display_help(void){
	uint8_t tx_data[24][40] = {

	      {"\r\nR Read BRT Register  		   "},
	      {"\r\nM Modify  BRT TX Buffer 		   "},
	      {"\r\nD Display BRT  TX/RX Buffer Data"},
	      {"\r\nC Change the BRT Address(Default:0x4 "},
	      {"\r\nH Display This Menu        \r\n"}
	 };

	      UART_send(&g_stdio_uart, tx_data[0],sizeof(tx_data));


}
コード例 #13
0
void METER_init ( )
{
	// Try resetting the meter @ 128,000 baud
	UART_init(UART_128000_BAUD);
	UART_send(METER_reset, sizeof(METER_reset));

	// Try resetting the meter @ 600 baud
	UART_flush();
	UART_init(UART_600_BAUD);
	UART_send(METER_reset, sizeof(METER_reset));

	// Wait for responses
	__METER_poll_drdy();

	// Increase the baud rate to 128000 baud
	UART_send(METER_set_baud, sizeof(METER_set_baud));
	UART_flush();
	UART_init(UART_128000_BAUD);

	// Write configuration
	UART_send(METER_write_config0, sizeof(METER_write_config0));
	UART_send(METER_write_config1, sizeof(METER_write_config1));

	// Enable integrator on current channel, HPF on voltage channel
	UART_send(METER_write_config2, sizeof(METER_write_config2));

	// Set gain
	UART_send(METER_write_i_gain, sizeof(METER_write_i_gain));
	UART_send(METER_write_v_gain, sizeof(METER_write_v_gain));
	//UART_send(METER_write_ac_offset, sizeof(METER_write_ac_offset));

	// Set Rogowski coil integrator to 60Hz
	UART_send(METER_integrator_gain, sizeof(METER_integrator_gain));

	// Enable interrupt on DRDY
	UART_send(METER_write_interrupt_mask, sizeof(METER_write_interrupt_mask));
}
コード例 #14
0
ファイル: glove.c プロジェクト: TimofonicJunkRoom/Oldies
void get_glove_data (glove_data *data) {
  int sy,cs;
  
  UART_send (0x43);
  sy=UART_receive ();
  data->f1=UART_receive ();
  data->f2=UART_receive ();
  data->f3=UART_receive ();
  data->f4=UART_receive ();
  data->f5=UART_receive ();
  data->pitch=UART_receive ();
  data->raw=UART_receive ();
  cs=UART_receive ();
  if (sy!=0x80) {
    /* error */
  }
}
コード例 #15
0
uint8_t get_key_selection(void)
{

      uint8_t rx_data;
      uint8_t rx_size =0;



           do {
               rx_size = UART_get_rx(&g_stdio_uart, &rx_data,1);
           }while(rx_size == 0);

           //dp_display_text("\n\r Selected fuction is: ");
           UART_send (&g_stdio_uart, &rx_data,sizeof (rx_data));
           return rx_data;

    }
コード例 #16
0
int main()
{
	uint8_t adc_value[16];
	uint16_t adc_temp;
	
	UART_init(9600);
	ADC_Init();
	
	while(1)
	{
		delay();
		adc_temp = ADC_Read(0);
		adc_value[0] = adc_temp>>8;
		adc_value[1] = adc_temp;
		
		adc_temp = ADC_Read(1);
		adc_value[2] = adc_temp>>8;
		adc_value[3] = adc_temp;
		
		adc_temp = ADC_Read(2);
		adc_value[4] = adc_temp>>8;
		adc_value[5] = adc_temp;
		
		adc_temp = ADC_Read(3);
		adc_value[6] = adc_temp>>8;
		adc_value[7] = adc_temp;
		
		adc_temp = ADC_Read(4);
		adc_value[8] = adc_temp>>8;
		adc_value[9] = adc_temp;
		
		adc_temp = ADC_Read(5);
		adc_value[10] = adc_temp>>8;
		adc_value[11] = adc_temp;
		
		adc_temp = ADC_Read(6);
		adc_value[12] = adc_temp>>8;
		adc_value[13] = adc_temp;
		
		adc_temp = ADC_Read(7);
		adc_value[14] = adc_temp>>8;
		adc_value[15] = adc_temp;
		UART_send(adc_value, 16);
	}
}
コード例 #17
0
ファイル: display.c プロジェクト: parrosam/base_station
void print_degrees(UART_instance_t * this_uart, int deg)
{
	static uint8_t old_x_pixel = 0;
	static uint8_t old_y_pixel = 0;

	if (old_x_pixel > 80) {
		erase_block(this_uart, 75, 127, old_x_pixel+5, old_y_pixel-5);
	}
	else if (old_x_pixel < 80) {
		erase_block(this_uart, 85, 127, old_x_pixel-5, old_y_pixel-5);
	}
	else {
		erase_block(this_uart, 75, 127, 85, old_y_pixel-10);
	}

	deg += 90.0;				//Convert to range 0 to 180 degrees

	//Set location of degree printout
	set_x(this_uart, 64);
	set_y(this_uart, 64);
	delay();

	//Convert int to char array
	char buffer[4];
	sprintf(buffer, "%03d", deg);

	//Print degrees
	UART_send( this_uart, (const uint8_t *)&buffer, sizeof(buffer) );

	//Get locations of x and y pixels for head of the pendulum
	uint8_t x_pixel = 80 - cos(deg * PI / 180) * 50;
	uint8_t y_pixel = 127 - sin(deg * PI / 180) * 50;

	//Draw pendulum
	draw_line(this_uart, 80, 127, x_pixel, y_pixel);
	draw_circle(this_uart, x_pixel, y_pixel, 5);

	old_x_pixel = x_pixel;
	old_y_pixel = y_pixel;
}
コード例 #18
0
/* This function reads the user input such as address and data required for any
 * memory read/write operation
 *
 *  */
		void read_user_input (uint8_t *rx_char_ptr)
		{
		    uint8_t recv_char=0;
		    uint8_t size=0;
		    uint8_t index = 0;
		    for(index = 0; index < 10; index++)
		    {
		    	rx_char[index] = '0';
		    }
		    index = 0;
		    while(recv_char != CHAR_LINE_FEED)  //'\n'
		    {
		      size = UART_get_rx(&g_stdio_uart, &recv_char,1);
			  if(size > 0)
			  {

				  rx_char_ptr[index] = recv_char;
				  UART_send (&g_stdio_uart, (uint8_t *)&recv_char,sizeof(recv_char));
				  index++;
				  size = 0; // clear the rcvd flag
			  }
			}

		}
コード例 #19
0
/*****************************************************************************
 Send tx_uint as decimal number with leading zeros out via the UART
 ****************************************************************************/
void UART_send_uint(void) {
    tx_value = 0;
    while (tx_uint >= 9999) {
        tx_uint -= 10000;
        ++tx_value;
    }
    tx_value += '0';
    UART_send();

    tx_value = 0;
    while (tx_uint >= 1000) {
        tx_uint -= 1000;
        ++tx_value;
    }
    tx_value += '0';
    UART_send();
    
    tx_value = 0;
    while (tx_uint >= 100) {
        tx_uint -= 100;
        ++tx_value;
    }
    tx_value += '0';
    UART_send();

    tx_value = 0;
    while (tx_uint >= 10) {
        tx_uint -= 10;
        ++tx_value;
    }
    tx_value += '0';
    UART_send();

    tx_value = tx_uint + '0';
    UART_send();

    tx_value = '\n';
    UART_send();
}
コード例 #20
0
ファイル: UART.c プロジェクト: FlaumKoczwara/Terrain-Mapper
void UART_send_int(UART_Type *UARTx, int count)
{
	char bufor[11];
	int2string(count,bufor);
	UART_send(UARTx,bufor);
}
コード例 #21
0
//displays hex values for data received
void hexsend(int8_t data) {
	const char *hexdig = "0123456789ABCDEF";
	UART_send(hexdig[(data>>4)&0xF]);
	UART_send(hexdig[data&0xF]);
}
コード例 #22
0
ファイル: display.c プロジェクト: parrosam/base_station
void erase_block(UART_instance_t * this_uart, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
{
	uint8_t tx_buff[6] = {0x7C, 0x05, x1, y1, x2, y2};
	UART_send( this_uart, (const uint8_t *)&tx_buff, sizeof(tx_buff) );
}
コード例 #23
0
ファイル: display.c プロジェクト: parrosam/base_station
void erase_circle(UART_instance_t * this_uart, uint8_t x, uint8_t y, uint8_t r)
{
	uint8_t tx_buff[6] = {0x7C, 0x03, x, y, r, 0x00};
	UART_send( this_uart, (const uint8_t *)&tx_buff, sizeof(tx_buff) );
}
コード例 #24
0
ファイル: display.c プロジェクト: parrosam/base_station
void erase_line(UART_instance_t * this_uart, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
{
	uint8_t tx_buff[7] = {0x7C, 0x0C, x1, y1, x2, y2, 0x00};
	UART_send( this_uart, (const uint8_t *)&tx_buff, sizeof(tx_buff) );
}
コード例 #25
0
ファイル: display.c プロジェクト: parrosam/base_station
void set_y(UART_instance_t * this_uart, uint8_t y){
	uint8_t tx_buff[3] = {0x7C, 0x19, y};
	UART_send( this_uart, (const uint8_t *)&tx_buff, sizeof(tx_buff) );
}
コード例 #26
0
ファイル: display.c プロジェクト: parrosam/base_station
void clear_screen(UART_instance_t * this_uart)
{
	uint8_t tx_buff[2] = {0x7C, 0x00};
	UART_send( this_uart, (const uint8_t *)&tx_buff, sizeof(tx_buff) );
}
コード例 #27
0
int main(){
	pwm_init();
	MSS_GPIO_init();
	range_init();
	MSS_GPIO_config(MSS_GPIO_31, MSS_GPIO_OUTPUT_MODE);
	UART_init(&g_uart, COREUARTAPB0_BASE_ADDR, 162, (DATA_8_BITS | NO_PARITY));

	uint8_t buff[BUFFER_SIZE];
	int offset = 0;
	size_t received;
	int joyx, joyy, cx, cy, start, fire;
	int startDown = 0;
	int mode = 0; // 0 for manual, 1 for automatic
	uint8_t tx[100];
	int txSize;
	firing = 0;
	curr_angle = 0;

	MSS_GPIO_set_output(MSS_GPIO_31, 0);

	/*while(1) {
		wheel2(255);
		//wheel4(255);
		//wheel2(-255);
		//wheel3(255);
		//wheel4(-255);
	}*/
	while (1) {
		while (!(received = UART_get_rx(&g_uart, buff+offset, sizeof(buff)-offset)));
		offset += received;
		//printf("Received: %d\n\r", received);
		if (buff[offset-1] == '\0') { // message fully received
			//printf("%s\n\r", buff);
			if (6 != sscanf(buff, "%d %d %d %d %d %d", &joyx, &joyy, &cx, &cy, &fire, &start)) {
				bzero(buff, BUFFER_SIZE);
				continue;
			}
			offset = 0;

			if (start && !startDown) {
				mode = !mode;
				startDown = 1;
			}
			if (!start && startDown)
				startDown = 0;

			joyx = joyx * .65;
			joyy = joyy * .65;

			if (joyx < 0)
				joyx -= 150;
			else if (joyx > 0)
				joyx += 150;
			if (joyy < 0)
				joyy -= 150;
			else if (joyy > 0)
				joyy += 150;

			printf("JoyX: %3d, JoyY: %3d, CX: %3d, CY: %3d, Fire: %d, Start: %d\n\r", joyx, joyy, cx, cy, fire, start);

			wheel1(joyy);
			wheel2(joyx);
			wheel3(joyy);
			wheel4(joyx);

			moveTurret(cy);

			if (fire && !firing) {
				start_gun();
			}

			if (firing && fire_counter <= FIRE_TIME)
				fire_counter++;
			if (!fire && firing && fire_counter >= FIRE_TIME)
				stop_gun();

		}
		else continue;
		txSize = sprintf(tx, "%d %d", mode, get_range()) + 1;
		UART_send(&g_uart, tx, txSize);
	}
	/*while(1){
		set_gun_angle(0);
		wheel1(-255);
    }*/
    return 0;
}
コード例 #28
0
ファイル: bluetooth.c プロジェクト: krucios/Astraeus_FW
inline void BT_send(const uint8_t* tx_buf, size_t size) {
    UART_send(&g_bt, tx_buf, size);
}
コード例 #29
0
void modify_mem_data (uint16_t addr,uint8_t ByteCount){

 uint16_t   mem_addr,mem_data;

 uint8_t recv_char=0;
 uint8_t size, index = 0;
 uint16_t input_data;

 uint8_t   i=0;
 uint8_t   m=0;
 uint8_t   key;

 /* Clear the buffer before getting any new data */
 for(index = 0; index < 10; index++)
			{
				rx_char[index] = '0';
			}
index = 0;

  mem_addr = addr;

 dp_display_text("Enter New data(0x10fe,1234, 0b1010110)\r\n");

 for ( i=0; i <= ByteCount ;i++) {
	dp_display_text("\r\n");
	dp_display_value(i,DEC);
	dp_display_text("\t");
	dp_display_value(mem_addr,HEX);
	dp_display_text(":");
	mem_data= HW_get_16bit_reg(mem_addr);
	dp_display_value(mem_data,HEX);
	dp_display_text("->");
	key = get_key_selection();
	if ( key == CHAR_ESC){  // ESC key == exit from writing
		return;
	}else if ( key == CHAR_LINE_FEED) // Return key, move to next address
	{
	  mem_addr = mem_addr + 1;
	} else

	{
		rx_char[0] = key;  // put the previosly rxvd character to buffer;

		index = 1;
					while(recv_char != CHAR_LINE_FEED)  //'\n'
					{
					  size = UART_get_rx(&g_stdio_uart, &recv_char,1);
					  if(size > 0)
					  {

						  rx_char[index] = recv_char;
						  UART_send (&g_stdio_uart, (uint8_t *)&recv_char,sizeof(recv_char));
						  index++;
						  size = 0; // clear the rcvd flag
					  }
					}

					rx_char_ptr = rx_char;
					xatoi ( &rx_char_ptr, &input_data);
					HW_set_16bit_reg(mem_addr,input_data);
					mem_addr = mem_addr + 1;
					recv_char = '-';  // DUMMY VALUE TO CHANGE THE DETECTION OF NEW LINE CHAR

	}


	}

 }