1993 views|4 replies

1452

Posts

1

Resources
The OP
 

[National Technology N32G457 Review] ML component control [Copy link]

 This post was last edited by jinglixixi on 2022-2-7 20:43

N32G457 provides multiple serial ports for use. Providing these serial ports can greatly expand the functions of the development board, because there are currently a variety of serial port-based functional modules to choose from and use, such as serial port-based MP3 voice playback module, serial port-based touch display, serial port-based ultrasonic sensor, etc. It is very important to master the use of serial ports.

Here we introduce an example of using a serial port to drive an ML component. It can encapsulate the detected data into data that drives the ML component and send it to the host computer via the serial port to intuitively indicate data changes with dynamic changes.

There are many types of ML components, such as scales, instrument panels, batteries, progress balls, and digital tubes. Figure 1 is a display interface made with ML components, and Figure 2 shows the display effect driven by data.

Figure 1 ML display interface

Figure 2 Data driven effect

The data encapsulation of ML components is relatively complex. To facilitate porting and use, we wrote the corresponding data encapsulation function according to its structure, and stored the encapsulation results in an array for serial port transmission.

The corresponding array initial values are:

char zl[20]={0x58, 0x5A, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

char data[4]={0x00, 0x00, 0x00, 0x00};

The function to implement floating point conversion is:

void updateCanvas(char * data, unsigned short datalen)
{
 zl[17]= data[2];
 zl[18]= data[3];
}

The data encapsulation function of the ML component is:

void change(uint8_t i, uint8_t n)
{
 uint8_t CV;
 CV=0xC9;
 if(i==0)
 {
 zl[9]=0xEF;
 }
 if(i==1)
 {
 zl[9]=0xE9;
 }
 if(i==2)
 {
 zl[9]=0xEA;
 }
 if(i==3)
 {
 zl[9]=0xF2;
 }
 if(i==4)
 {
 zl[9]=0xEB;
 }
 ...
 if(n==0)
 {
 zl[11]=0x00;
 }
 if(n==1)
 {
 zl[11]=0x01;
 }
 if(n==2)
 {
 zl[11]=0x02;
 }
 ...

 CV=CV+zl[9]+zl[11]+zl[17]+zl[18];
 zl[19]=CV;
}

The serial port sending function used is:

void Uart_Send(void)
{
 uint8_t i;
 for(i=0;i<20;i++)
 {
  USART_SendData(USARTx,zl);
 while (USART_GetFlagStatus(USARTx, USART_FLAG_TXDE) == RESET);
 }
}

The main program to achieve the driving effect shown in Figure 2 is:

int main(void)
{
 float x = 57;
 RCC_Configuration();
 GPIO_Configuration();
 USART_InitStructure.BaudRate = 9600;
 USART_InitStructure.WordLength = USART_WL_8B;
 USART_InitStructure.StopBits = USART_STPB_1;
 USART_InitStructure.Parity = USART_PE_NO;
 USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;
 USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX;
 USART_Init(USARTx, &USART_InitStructure);
 USART_Enable(USARTx, ENABLE);
 updateCanvas( (char *)&x, sizeof(float));
 change(1, 0);
 Uart_Send();
 SysTick_Delay_Ms(100);
 x = 60;
 updateCanvas( (char *)&x, sizeof(float));
 change(2, 0);
 Uart_Send();
 SysTick_Delay_Ms(100);
 x = 26;
 updateCanvas( (char *)&x, sizeof(float));
 change(3, 0);
 Uart_Send();
 SysTick_Delay_Ms(100);
 x = 75;
 updateCanvas( (char *)&x, sizeof(float));
 change(3, 1);
 Uart_Send();
 SysTick_Delay_Ms(100);
 x = 1024;
 updateCanvas( (char *)&x, sizeof(float));
 change(4, 1);
 Uart_Send();
 SysTick_Delay_Ms(100);
 x = 720;
 updateCanvas( (char *)&x, sizeof(float));
 change(4, 0);
 Uart_Send();
 SysTick_Delay_Ms(100);
 while (1);
}
The test result using the serial port debugging tool is shown in Figure 3. Based on this program, dynamic data indication can be achieved by connecting corresponding sensors.

Figure 3 Serial port test results

This post is from Domestic Chip Exchange

Latest reply

I strongly support domestic chips and hope that everyone will use more domestic chips   Details Published on 2024-3-6 08:33
 
 

6555

Posts

0

Resources
2
 

The serial port driver ML component display interface is relatively intuitive

Serial port expansion does have many uses

This post is from Domestic Chip Exchange
 
 
 

1452

Posts

1

Resources
3
 
Jacktang posted on 2022-2-9 07:31 The display interface of the serial port driver ML component is relatively intuitive. The serial port expansion has many uses.

This post is from Domestic Chip Exchange
 
 
 

25

Posts

0

Resources
4
 

I strongly support domestic chips and hope that everyone will use more domestic chips

This post is from Domestic Chip Exchange

Comments

I agree!!!  Details Published on 2024-3-6 10:51
 
 
 

1452

Posts

1

Resources
5
 
humancat01 posted on 2024-3-6 08:33 I strongly support domestic chips and hope that everyone will use more domestic chips

I agree!!!

This post is from Domestic Chip Exchange
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list