usart

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

usart

472件の閲覧回数
syedhashmiraza
Contributor III

"I am using the LPC55S16 microcontroller, and I am sending 20 bytes of data. After receiving, when I print it, I am only getting 16 bytes of data. How can I print the full 20 bytes of data? this is my code.

 

#include "pin_mux.h"
#include "board.h"
#include "fsl_usart.h"
#include <stdbool.h>
#include "fsl_power.h"
#include "stdio.h"

/*******************************************************************************
* Definitions
******************************************************************************/
#define DEMO_USART USART0
#define DEMO_USART_CLK_SRC kCLOCK_Flexcomm1
#define DEMO_USART_CLK_FREQ CLOCK_GetFlexCommClkFreq(0U)
#define DEMO_USART_IRQHandler FLEXCOMM0_IRQHandler
#define DEMO_USART_IRQn FLEXCOMM0_IRQn

/*! @brief Ring buffer size (Unit: Byte). */
#define DEMO_RING_BUFFER_SIZE 32

/*******************************************************************************
* Prototypes
******************************************************************************/
bool ISO7816_Write(uint8_t b);
bool ISO7816_Read(uint8_t* b);


uint32_t demoRingBuffer[DEMO_RING_BUFFER_SIZE];
volatile uint16_t txIndex;
volatile uint16_t rxIndex;
volatile uint16_t lastRxIndex; // Variable to store the last received index

bool ISO7816_Write(uint8_t b)
{
if (!(USART_GetStatusFlags(DEMO_USART) & kUSART_TxFifoNotFullFlag)) return false;
USART_WriteByte(DEMO_USART, b);
return true;
}

bool ISO7816_Read(uint8_t* b)
{
if (!(USART_GetStatusFlags(DEMO_USART) & kUSART_RxFifoNotEmptyFlag)) return false;
*b = USART_ReadByte(DEMO_USART);
rxIndex = (rxIndex + 1) % DEMO_RING_BUFFER_SIZE; // Update rxIndex
return true;
}

 

int main(void)
{

usart_config_t config;

POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();

 

USART_GetDefaultConfig(&config);
config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
config.enableTx = true;
config.enableRx = true;
USART_Init(DEMO_USART, &config, DEMO_USART_CLK_FREQ);

uint32_t sendDataIndex = 0; // Index to track the next byte to send
uint32_t i;
const char sendDataBuffer[] = "Hello";

for (size_t i = 0; i < sizeof(sendDataBuffer) - 1; ++i) {
ISO7816_Write(sendDataBuffer[i]);
}

while (1)
{


// Check for received data
uint8_t receivedData=0;
while (ISO7816_Read(&receivedData))
{
printf("receivedData=%x\n",receivedData);
// lastRxIndex = rxIndex; // Update last received index
}
}
}

タグ(1)
0 件の賞賛
返信
0 返答(返信)