main()
ниже звонков getdata()
, который непрерывно читает символы из uart в do while loop
. Он помещает их в массив, когда массив заполнен, он записывает их поверх uart.как вернуть массив от функции к main()
Как я могу получить это, чтобы просто заполнить массив один раз и вернуть его в main(), и я могу записать его в main()?
int main(void)
{
getdata();
//How can I return the array once to main and write it out over uart()?
}
void getdata(void)
{
static uint8_t detected = 0;
static uint8_t ndx;
char receiveddata[6];
char retchar;
do{
retdata = getch(); //read char from the uart
if ((retdata == 'Z') && (detected == 0))
{
detected = 1;
ndx = 0;
}
if ((detected == 1) && (ndx < 5))
{
receiveddata[ndx] = retdata;
ndx++;
}
if (retdata == '\r'){
receiveddata[ndx] = '\n';
ndx = 0;
detected = 0;
uart_write_buffer(UART_4, (uint8_t *)receiveddata, sizeof(receiveddata));
}
}while(1);
}