void putchar3(int ch) { unsigned char buf[2] = {0}; buf[0] = ch; if (ch == '\n') { buf[1] = '\n'; buf[0] = '\r'; UART_Send((LPC_UART_TypeDef *)FPGA_UART3_PORT, (unsigned char *)buf, 2, BLOCKING); } else { UART_Send((LPC_UART_TypeDef *)FPGA_UART3_PORT, (unsigned char *)buf, 1, BLOCKING); } }
uint8 SendCOM0(void *buf,uint32 len) { uint8 station; if( (!len) ) { return FALSE; } station = GetUart0Status(); while(!(station & (0x01<<6))) { station = GetUart0Status(); } WriteEN_485_0(1); UART_Send((LPC_UART_TypeDef *)LPC_UART0,buf,len,BLOCKING); station = GetUart0Status(); while(!(station & (0x01<<6))) { station = GetUart0Status(); } WriteEN_485_0(0); return TRUE; }
static void CheckForFwIdentMessage() { g_Odd_STX_Received = !g_Odd_STX_Received; if (g_Odd_STX_Received == FALSE) { UART_Send(FW_IDENT); } }
static rt_size_t rt_uart_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) { struct rt_uart_lpc *uart = (struct rt_uart_lpc*)dev; char *ptr; ptr = (char*)buffer; if (dev->flag & RT_DEVICE_FLAG_STREAM) { /* stream mode */ while (size) { if (*ptr == '\n') { while (!(uart->UART->LSR & UART_LSR_THRE)); UART_SendByte( uart->UART,'\r'); } while (!(uart->UART->LSR & UART_LSR_THRE)); UART_SendByte( uart->UART,*ptr); ptr ++; size --; } } else { UART_Send( uart->UART, (uint8_t *)buffer, size, BLOCKING); } return (rt_size_t) ptr - (rt_size_t) buffer; }
/********************************************************************//** * @brief UART transmit function (ring buffer used) * @param[in] None * @return None *********************************************************************/ void UART1_IntTransmit(void) { // Disable THRE interrupt UART_IntConfig((LPC_UART_TypeDef *)LPC_UART1, UART_INTCFG_THRE, DISABLE); /* Wait for FIFO buffer empty, transfer UART_TX_FIFO_SIZE bytes * of data or break whenever ring buffers are empty */ /* Wait until THR empty */ while (UART_CheckBusy((LPC_UART_TypeDef *)LPC_UART1) == SET); while (!__BUF_IS_EMPTY(rb.tx_head,rb.tx_tail)) { /* Move a piece of data into the transmit FIFO */ if (UART_Send((LPC_UART_TypeDef *)LPC_UART1, (uint8_t *)&rb.tx[rb.tx_tail], \ 1, NONE_BLOCKING)){ /* Update transmit ring FIFO tail pointer */ __BUF_INCR(rb.tx_tail); } else { break; } } /* If there is no more data to send, disable the transmit interrupt - else enable it or keep it enabled */ if (__BUF_IS_EMPTY(rb.tx_head, rb.tx_tail)) { UART_IntConfig((LPC_UART_TypeDef *)LPC_UART1, UART_INTCFG_THRE, DISABLE); // Reset Tx Interrupt state TxIntStat = RESET; } else{ // Set Tx Interrupt state TxIntStat = SET; UART_IntConfig((LPC_UART_TypeDef *)LPC_UART1, UART_INTCFG_THRE, ENABLE); } }
static uint32_t GSM_SerialSendString(uint8_t* ptr ) { uint32_t nrOfBytesSend; nrOfBytesSend = UART_Send(UARTx, ptr, buffLength(ptr), BLOCKING); while(UART_CheckBusy(UARTx)); return nrOfBytesSend; }
int serialUSBWrite(char *buffer) { int string_len; string_len = strlen(buffer); return(UART_Send((LPC_UART_TypeDef *)LPC_UART0, (uint8_t *)buffer, string_len, BLOCKING)); }
/** @brief Send a character via UART * * @param [in] uart The UART on which to send the character * @param [in] c The character to send * * @return None. * * Blocks until the UART is ready to accept the new character, then * writes it. */ void uart_putchar(UART_Type *uart, uint8_t c) { /* Wait for tx holding register to empty */ while ((UART_GetLineStatus(uart) & UART_LineStatus_TxEmpty) == 0); /* Send character */ UART_Send(uart, c); }
/*********************************************************************//** * @brief Send data on RS485 bus with specified parity stick value (9-bit mode). * @param[in] UARTx LPC_UART1 (only) * @param[in] pDatFrm Pointer to data frame. * @param[in] size Size of data. * @param[in] ParityStick Parity Stick value, should be 0 or 1. * @return None **********************************************************************/ uint32_t UART_RS485Send(LPC_UART1_TypeDef *UARTx, uint8_t *pDatFrm, \ uint32_t size, uint8_t ParityStick) { uint8_t tmp, save; uint32_t cnt; if (ParityStick){ save = tmp = UARTx->LCR & UART_LCR_BITMASK; tmp &= ~(UART_LCR_PARITY_EVEN); UARTx->LCR = tmp; cnt = UART_Send((LPC_UART_TypeDef *)UARTx, pDatFrm, size, BLOCKING); while (!(UARTx->LSR & UART_LSR_TEMT)); UARTx->LCR = save; } else { cnt = UART_Send((LPC_UART_TypeDef *)UARTx, pDatFrm, size, BLOCKING); while (!(UARTx->LSR & UART_LSR_TEMT)); } return cnt; }
void __putchar(int ch) { unsigned char buf[2] = {0}; buf[0] = ch & 0xff; if (ch == 0xa) { buf[0] = 0xa; buf[1] = 0; //UART_Send((LPC_UART_TypeDef *)CONSOLE_UART_PORT, (unsigned char *)buf, 2, BLOCKING); UART_Send((LPC_UART_TypeDef *)CONSOLE_UART_PORT, (unsigned char *)buf, 1, BLOCKING); buf[0] = 0xd; buf[1] = 0; UART_Send((LPC_UART_TypeDef *)CONSOLE_UART_PORT, (unsigned char *)buf, 1, BLOCKING); } else { UART_Send((LPC_UART_TypeDef *)CONSOLE_UART_PORT, (unsigned char *)buf, 1, BLOCKING); } }
void GPS_Wakeup() { CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART3, ENABLE); //Send GPS Sleep command uint8_t wakeCmd = ' '; UART_Send(UART_3, &wakeCmd, 1, BLOCKING); //Set state to GPS on gpsActive = 1; }
void ATTR_VISIBLE panic_internal(const char *fmt, ...) { va_list va; char buffer[80]; int n; va_start(va, fmt); n = vsnprintf(buffer, sizeof(buffer) - 2, fmt, va); if (n > (sizeof(buffer) - 2)) n = sizeof(buffer) - 2; buffer[n] = '\r'; buffer[n + 1] = '\n'; UART_Send(DEBUG_UART, (uint8_t *) PANIC_STRING, sizeof(PANIC_STRING), BLOCKING); UART_Send(DEBUG_UART, (uint8_t *) buffer, n + 2, BLOCKING); while (1); }
void GPS_Sleep() { //Send GPS Sleep command uint8_t* sleepCmd = (uint8_t*)"$PMTK161,0*28\r\n"; UART_Send(UART_3, sleepCmd, 15, BLOCKING); CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART3, DISABLE); //Set state to GPS off gpsActive = 0; gpsData.valid = 0; }
void SND_SetVol(uint8_t SndVol) { uint8_t vol = 0; if(SndVol < SND_VOL_MIN) vol = SND_VOL_MIN; else if(SndVol > SND_VOL_MAX) vol = SND_VOL_MAX; else vol = SndVol; UART_Send(UART_2, VOL[vol], 5, BLOCKING); }
void SND_SelectID(uint8_t SndID) { uint8_t id = 0; if(SndID < SND_ID_MIN) id = SND_ID_MIN; else if(SndID > SND_ID_MAX) id = SND_ID_MAX; else id = SndID; UART_Send(UART_2, SND[SndID-1], 6, BLOCKING); }
void test_btm_send_idle(void) { uint8 rst = 0; uint32 send_num = 0; BTM_CreateFrameSN(); // 每次发送报文时,ID自增1 BTM_IdleFrameInit(); BTM_IdleLoad(frameSN, frameDataSN); BTM_PackIdlePacket_BtmA(); rst = BTM_PackSinoPacket_BtmA(btmAIdleFrameBuf); if (rst == 1) { send_num = UART_Send(btmAFd, (char *)btmASendBuf, BTM_SEND_BUF_SIZE); } else { send_num = UART_Send(btmAFd, (char *)btmASendBuf, (BTM_SEND_BUF_SIZE - 1)); } //DBG_INFO("[BTM] btm send num %d\n", send_num); }
/*----------------------------------------------------------------------------- * Transmit Call-back dispatch for UART driver *-----------------------------------------------------------------------------*/ void UartTxCallBack(void) { uint8_t tmpc; if (!__BUF_EMPTY(BufTx)) { tmpc = __BUF_RD(BufTx); UART_Send(UARTInfo.pUart, &tmpc, 1, BLOCKING); TxRestart = 0; } else { /* disable TX interrupt if nothing to send */ UART_IntConfig(UARTInfo.pUart, UART_INTCFG_THRE, DISABLE); TxRestart = 1; } }
/* With ARM and GHS toolsets, the entry point is main() - this will allow the linker to generate wrapper code to setup stacks, allocate heap area, and initialize and copy code and data segments. For GNU toolsets, the entry point is through __start() in the crt0_gnu.asm file, and that startup code will setup stacks and data */ int main(void) { uchar buffer,buf[10]; System_Init(); // print welcome screen print_menu(LPC_UART0); print_menu(LPC_UART2); /* Read some data from the buffer */ while (1) { buffer = getche(LPC_UART0); /* Got some data */ if (EscFlag) { UART_Send(LPC_UART2, menu3, sizeof(menu3), BLOCKING); break; } if (buffer == 'r') { print_menu(LPC_UART2); get_line(LPC_UART0,buf,6); printf(LPC_UART2,buf); } else { /* Echo it back */ UART_SendByte((LPC_UART_TypeDef *)LPC_UART2, buffer); } } // wait for current transmission complete - THR must be empty while (UART_CheckBusy(LPC_UART0) == SET); while (UART_CheckBusy(LPC_UART2) == SET); // DeInitialize UART0 peripheral UART_DeInit(LPC_UART0); UART_DeInit(LPC_UART2); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief UART Line Status Error * @param[in] bLSErrType UART Line Status Error Type * @return None **********************************************************************/ void UART_IntErr(uint8_t bLSErrType) { uint8_t tmp; #if (RECEIVER_ALWAYS_EN) uint8_t tmpc; if (bLSErrType & UART_LSR_PE){ // Parity error means the latest frame receive is slave address frame, // Value of slave address is read and trimmed out. UART_Send(LPC_UART0, p_err_menu, sizeof(p_err_menu), BLOCKING); UART_Send(LPC_UART0, addr_menu, sizeof(addr_menu), BLOCKING); UART_Receive((LPC_UART_TypeDef *)LPC_UART1, &tmpc, 1, NONE_BLOCKING); } if (bLSErrType & UART_LSR_FE){ UART_Send(LPC_UART0, f_err_menu, sizeof(f_err_menu), BLOCKING); } #else #if (AUTO_SLVADDR_DETECT == 0) uint8_t tmp; // Check if this interrupt caused by parity error, // that means the last received frame is address frame, // if this address is matched with its own address, // continue to receive following data frame. if (bLSErrType & UART_LSR_PE){ UART_Receive((UART_TypeDef *)UART1, &tmp, 1, NONE_BLOCKING); UART_Send(UART0, p_err_menu, sizeof(p_err_menu), BLOCKING); if (tmp == SLAVE_ADDR){ UART_RS485ReceiverCmd(UART1, ENABLE); UART_Send(UART0, addr_acc, sizeof(addr_acc), BLOCKING); } else { // Disable receiver UART_RS485ReceiverCmd(UART1, DISABLE); UART_Send(UART0, addr_una, sizeof(addr_una), BLOCKING); } } #else // Check if this interrupt caused by parity error, // that means the last received frame is address frame, // if this address is matched with its own address, // continue to receive following data frame. if (bLSErrType & UART_LSR_PE){ UART_Receive((LPC_UART_TypeDef *)LPC_UART1, &tmp, 1, NONE_BLOCKING); UART_Send(LPC_UART0, addr_auto, sizeof(addr_auto), BLOCKING); } #endif #endif }
int main(int argc, char **argv) { int serial_fd = 0; UART_Init(); char buf[]="hello world"; char buf1[10]; UART_Send(serial_fd, buf, 10); printf("\n"); UART_Recv(serial_fd, buf1, 10); printf("uart receive %s\n", buf1); close(serial_fd); return 0; }
int main(int argc, char **argv) { int fd = FALSE; int ret; char rcv_buf[512]; char send_buf[512]; int i; if(argc != 2){ printf("Usage: %s /dev/ttySn \n",argv[0]); return FALSE; } fd = UART_Open(fd,argv[1]); if(FALSE == fd){ printf("open error\n"); exit(1); } ret = UART_Init(fd,9600,0,8,1,'N'); if (FALSE == fd){ printf("Set Port Error\n"); exit(1); } strcpy(send_buf,"ff0161\n"); ret = UART_Send(fd,send_buf,strlen(send_buf)); if(FALSE == ret){ printf("write error!\n"); exit(1); } printf("command: %s\n",send_buf); memset(rcv_buf,0,sizeof(rcv_buf)); for(i=0;;i++) { ret = UART_Recv(fd, rcv_buf,512); if( ret > 0){ rcv_buf[ret]='\0'; printf("%s",rcv_buf); } else { printf("cannot receive data1\n"); //break; } if('\n' == rcv_buf[ret-1]) break; } UART_Close(fd); return 0; }
void SND_SetVol(uint8_t SndVol) { uint8_t vol = 0; if(SndVol < SND_VOL_MIN) vol = SND_VOL_MIN; else if(SndVol > SND_VOL_MAX) vol = SND_VOL_MAX; else vol = SndVol; // vol = vol; // UART_Send(UART_0, VOL[vol], 5, BLOCKING); // UART_SendByte(UART_0, 0x7e); // UART_SendByte(UART_0, 0x03); // UART_SendByte(UART_0, 0x31); // UART_SendByte(UART_0, vol); // UART_SendByte(UART_0, 0x7e); }
tBoolean WiFly_Send(const char * send, const char * resp) { tBoolean status = true; unsigned char attempts = 0; while(attempts < MAX_ATTEMPTS) { delay250ms(); UART_Send((unsigned char*)send, strlen(send)); delay250ms(); if(!resp) break; // Case where no response is required if(WiFly_Match(resp)) break; attempts++; } // return failure if(attempts >= (MAX_ATTEMPTS - 1)) status = false; return status; }
int _UARTSendandReceive(uint8_t * args) { int n; uint8_t * arg_ptr; uint8_t txbuf[13], rxbuf[18]; uint32_t txbuflen=13, rxbuflen=18, length; for(n=0;n<txbuflen;n++) { if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; txbuf[n] = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); } UART_Send((LPC_UART_TypeDef*) LPC_UART1, txbuf, txbuflen, BLOCKING); //Reception length = UART_Receive((LPC_UART_TypeDef*) LPC_UART1, rxbuf, rxbuflen, NONE_BLOCKING); sprintf((char *) str, "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\r\n", rxbuf[0], rxbuf[1], rxbuf[2], rxbuf[3], rxbuf[4], rxbuf[5],rxbuf[6], rxbuf[7], rxbuf[8], rxbuf[9], rxbuf[10], rxbuf[11], rxbuf[12], rxbuf[13], rxbuf[14], rxbuf[15], rxbuf[16], rxbuf[17]); writeUSBOutString(str); return 0; }
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { if (htim->Instance == htim1.Instance) { HAL_GPIO_TogglePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin); } else if (htim->Instance == htim2.Instance) { char *buffer = malloc(sizeof(char) * 16); uint32_t value = getAdcValue(nextChannel); int l = sprintf(buffer, "%d: %08ld\n", nextChannel, value); UART_Send((uint8_t *)buffer, l); nextChannel++; if (nextChannel == 3) { nextChannel = 0; } } }
int fputc(int ch, FILE *f) { uint8_t byte = ch; #if DEBUG_MODE_UART UART_Send((const uint8_t *)&byte, sizeof(uint8_t)); #endif /* DEBUG_MODE_UART */ #if DEBUG_MODE_RADIO RADIO_TX(&byte, 1); #endif /* DEBUG_MODE_RADIO */ #if DEBUG_MODE_FLASH if (currentFLASHWriteAddress < ADDRESS_LOG_END) { if (LX_FIFOIsFull(fifoFLASH)) { MX25L4006E_WakeUp(); uint8_t buf[FLASH_FIFO_SIZE] = {0}; LX_FIFORead(fifoFLASH, buf, sizeof(buf)); MX25L4006E_Write(currentFLASHWriteAddress, buf, sizeof(buf), 300); currentFLASHWriteAddress += sizeof(buf); } } LX_FIFOWrite(fifoFLASH, &byte, 1); #endif /* DEBUG_MODE_FLASH */ return ch; }
int main() { int u; u = InitSerial(); if( u == -1 ) { fprintf(stderr,"InitSerial Error!\n"); return -1; } char *buffer = (char*)malloc(8*sizeof(char)); *buffer = 0xff; *(buffer+1) = 0xff; *(buffer+2) = 0xfe;//broadcast *(buffer+3) = 0x04; *(buffer+4) = 0x03;//write data *(buffer+5) = 0x04; *(buffer+6) = 0x01; int sum; sum = 0xfe; sum += 0x04; sum += 0x03; sum += 0x04+1; sum = sum&0xff; sum = ~sum; char *chsum = (char*)malloc(sizeof(char)); memcpy(chsum,&sum,sizeof(char)); *(buffer+7) = *chsum;//checksum char todisplay[50]; char * p_display=todisplay; memset(p_display,0,50*sizeof(char)); ByteToHexStr(buffer,p_display,8*sizeof(char)); printf("Sending:\n %s \n",p_display); UART_Send(u,buffer,8*sizeof(char)); free(buffer); close(u); }
void handleTransmitInterrupt() { disableTransmitInterrupt(); if(CTS_STATE == INACTIVE) { return; } while(UART_CheckBusy(UART1_DEVICE) == SET); while(!QUEUE_EMPTY(uint8_t, &listener.serial->sendQueue)) { uint8_t byte = QUEUE_PEEK(uint8_t, &listener.serial->sendQueue); if(UART_Send(UART1_DEVICE, &byte, 1, NONE_BLOCKING)) { QUEUE_POP(uint8_t, &listener.serial->sendQueue); } else { break; } } if(QUEUE_EMPTY(uint8_t, &listener.serial->sendQueue)) { disableTransmitInterrupt(); } else { enableTransmitInterrupt(); } }
uint32_t serialSend(uint8_t* txbuf, uint32_t len) { return(UART_Send(LPC_UART3, txbuf, len, BLOCKING)); }
//--------------------------------------------------------------------+ // UART //--------------------------------------------------------------------+ uint32_t board_uart_send(uint8_t *p_buffer, uint32_t length) { return UART_Send((LPC_USARTn_Type*) LPC_USART0, p_buffer, length, BLOCKING); }