Implemented UART communication (initial version). Needs more testing and make the buffer smaller to save space. RX and TX have been swapped in the system for debug (bad solder joint).
This commit is contained in:
parent
35e0e1fadc
commit
23f1f27c0e
@ -47,8 +47,8 @@
|
||||
* Desired interrupt period 60s
|
||||
*/
|
||||
const uint16_t tim21_prescaler = 60000-1; // 100Hz
|
||||
const uint16_t tim21_period = 12000-1; // 60s
|
||||
//const uint16_t tim21_period = 1200-1; // 6s
|
||||
//const uint16_t tim21_period = 12000-1; // 60s
|
||||
const uint16_t tim21_period = 1200-1; // 6s
|
||||
//const uint16_t tim21_period = 200-1; // 1s
|
||||
/* USER CODE END PV */
|
||||
|
||||
@ -158,6 +158,11 @@ int main(void)
|
||||
if (lpuart1_rx_done == 1)
|
||||
{
|
||||
/* Process the message */
|
||||
uint8_t buff_pom[255];
|
||||
for (uint8_t j = 0; j < lpuart1_rx_message_len; j ++)
|
||||
{
|
||||
buff_pom[j] = lpuart1_rx_message[j];
|
||||
}
|
||||
/* process_modbus_message(lpuart1_rx_message, lpuart1_rx_message_len); */
|
||||
|
||||
/* Reset the RX DONE flag */
|
||||
@ -193,6 +198,9 @@ int main(void)
|
||||
tim21_elapsed_period = 0;
|
||||
}
|
||||
/* TEST START */
|
||||
|
||||
//LL_LPUART_TransmitData9(LPUART1, 0x69);
|
||||
//LL_mDelay(250);
|
||||
/* TODO: DELETE TEST */
|
||||
|
||||
/* RS485 test */
|
||||
@ -350,11 +358,9 @@ static void MX_LPUART1_UART_Init(void)
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_LPUART1);
|
||||
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
|
||||
/**LPUART1 GPIO Configuration
|
||||
PA0-CK_IN ------> LPUART1_RX
|
||||
PA1 ------> LPUART1_TX
|
||||
PB1 ------> LPUART1_DE
|
||||
*/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
@ -372,14 +378,6 @@ static void MX_LPUART1_UART_Init(void)
|
||||
GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
GPIO_InitStruct.Alternate = LL_GPIO_AF_4;
|
||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* LPUART1 interrupt Init */
|
||||
NVIC_SetPriority(LPUART1_IRQn, 0);
|
||||
NVIC_EnableIRQ(LPUART1_IRQn);
|
||||
@ -394,10 +392,7 @@ static void MX_LPUART1_UART_Init(void)
|
||||
LPUART_InitStruct.TransferDirection = LL_LPUART_DIRECTION_TX_RX;
|
||||
LPUART_InitStruct.HardwareFlowControl = LL_LPUART_HWCONTROL_NONE;
|
||||
LL_LPUART_Init(LPUART1, &LPUART_InitStruct);
|
||||
LL_LPUART_EnableDEMode(LPUART1);
|
||||
LL_LPUART_SetDESignalPolarity(LPUART1, LL_LPUART_DE_POLARITY_HIGH);
|
||||
LL_LPUART_SetDEAssertionTime(LPUART1, 0);
|
||||
LL_LPUART_SetDEDeassertionTime(LPUART1, 0);
|
||||
LL_LPUART_SetTXRXSwap(LPUART1, LL_LPUART_TXRX_SWAPPED);
|
||||
/* USER CODE BEGIN LPUART1_Init 2 */
|
||||
|
||||
/* Enable IDLE Interrupt */
|
||||
@ -406,6 +401,9 @@ static void MX_LPUART1_UART_Init(void)
|
||||
/* Enable RX Not Empty Interrupt */
|
||||
LL_LPUART_EnableIT_RXNE(LPUART1);
|
||||
|
||||
LL_LPUART_EnableDirectionRx(LPUART1);
|
||||
LL_LPUART_EnableDirectionTx(LPUART1);
|
||||
LL_LPUART_Enable(LPUART1);
|
||||
/* USER CODE END LPUART1_Init 2 */
|
||||
|
||||
}
|
||||
@ -460,7 +458,6 @@ static void MX_GPIO_Init(void)
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
|
||||
|
||||
/**/
|
||||
LL_GPIO_SetOutputPin(LED_B_GPIO_Port, LED_B_Pin);
|
||||
|
@ -179,13 +179,13 @@ void LPUART1_IRQHandler(void)
|
||||
/* USER CODE END LPUART1_IRQn 0 */
|
||||
/* USER CODE BEGIN LPUART1_IRQn 1 */
|
||||
/* If the IDLE flag is active */
|
||||
if (LL_LPUART_IsActiveFlag_IDLE(LPUART1) == 1)
|
||||
if (LL_LPUART_IsActiveFlag_IDLE(LPUART1) && LL_LPUART_IsEnabledIT_IDLE(LPUART1))
|
||||
{
|
||||
/* Clear the IDLE flag */
|
||||
LL_LPUART_ClearFlag_IDLE(LPUART1);
|
||||
|
||||
/* Reset the buffer index */
|
||||
lpuart1_rx_message_len = lpuart1_rx_message_index + 1;
|
||||
lpuart1_rx_message_len = lpuart1_rx_message_index;
|
||||
lpuart1_rx_message_index = 0;
|
||||
lpuart1_rx_done = 1;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ ProjectManager.ProjectFileName=iaq_wired_sensor.ioc
|
||||
ProjectManager.KeepUserCode=true
|
||||
PA10.Mode=I2C
|
||||
Mcu.UserName=STM32L011F4Ux
|
||||
Mcu.PinsNb=12
|
||||
Mcu.PinsNb=11
|
||||
ProjectManager.NoMain=false
|
||||
TIM21.IPParameters=Prescaler,Period,AutoReloadPreload,ClockDivision
|
||||
PA0-CK_IN.Mode=Asynchronous
|
||||
@ -34,8 +34,8 @@ ProjectManager.StackSize=0x400
|
||||
RCC.WatchDogFreq_Value=37000
|
||||
PA13.Signal=SYS_SWDIO
|
||||
Mcu.IP4=SYS
|
||||
RCC.HSI16_VALUE=16000000
|
||||
RCC.FCLKCortexFreq_Value=12000000
|
||||
RCC.HSI16_VALUE=16000000
|
||||
Mcu.IP5=TIM21
|
||||
I2C1.IPParameters=Timing
|
||||
Mcu.IP2=NVIC
|
||||
@ -58,11 +58,11 @@ RCC.APB2TimFreq_Value=12000000
|
||||
PA9.Signal=I2C1_SCL
|
||||
I2C1.Timing=0x40000A0B
|
||||
LPUART1.Parity=UART_PARITY_EVEN
|
||||
Mcu.Pin6=PA9
|
||||
Mcu.Pin7=PA10
|
||||
Mcu.Pin6=PA10
|
||||
Mcu.Pin7=PA13
|
||||
ProjectManager.RegisterCallBack=
|
||||
Mcu.Pin8=PA13
|
||||
Mcu.Pin9=PA14
|
||||
Mcu.Pin8=PA14
|
||||
Mcu.Pin9=VP_SYS_VS_Systick
|
||||
PA0-CK_IN.GPIO_PuPd=GPIO_PULLUP
|
||||
RCC.LSE_VALUE=32768
|
||||
PA1.GPIO_PuPd=GPIO_PULLUP
|
||||
@ -74,7 +74,7 @@ GPIO.groupedBy=Group By Peripherals
|
||||
Mcu.Pin2=PA5
|
||||
Mcu.Pin3=PA6
|
||||
Mcu.Pin4=PA7
|
||||
Mcu.Pin5=PB1
|
||||
Mcu.Pin5=PA9
|
||||
PA5.Signal=GPIO_Output
|
||||
ProjectManager.ProjectBuild=false
|
||||
RCC.HSE_VALUE=8000000
|
||||
@ -116,12 +116,11 @@ ProjectManager.UnderRoot=true
|
||||
ProjectManager.CoupleFile=false
|
||||
RCC.SYSCLKFreq_VALUE=12000000
|
||||
Mcu.Package=UFQFPN20
|
||||
PB1.Signal=LPUART1_DE
|
||||
PA6.Signal=GPIO_Output
|
||||
PA7.GPIO_Label=LED_R
|
||||
PA5.Locked=true
|
||||
PA7.Locked=true
|
||||
LPUART1.SwapParam=UART_ADVFEATURE_SWAP_DISABLE
|
||||
LPUART1.SwapParam=UART_ADVFEATURE_SWAP_ENABLE
|
||||
PA5.GPIO_Label=LED_B
|
||||
NVIC.ForceEnableDMAVector=true
|
||||
KeepUserPlacement=false
|
||||
@ -133,12 +132,10 @@ PA10.Signal=I2C1_SDA
|
||||
PA14.Signal=SYS_SWCLK
|
||||
ProjectManager.HeapSize=0x200
|
||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
PB1.Mode=Hardware Flow Control (RS485)
|
||||
PA5.GPIOParameters=PinState,GPIO_Label
|
||||
ProjectManager.ComputerToolchain=false
|
||||
RCC.HSI_VALUE=16000000
|
||||
Mcu.Pin11=VP_TIM21_VS_ClockSourceINT
|
||||
Mcu.Pin10=VP_SYS_VS_Systick
|
||||
Mcu.Pin10=VP_TIM21_VS_ClockSourceINT
|
||||
RCC.APB1TimFreq_Value=12000000
|
||||
RCC.PWRFreq_Value=12000000
|
||||
RCC.APB1Freq_Value=12000000
|
||||
|
Loading…
Reference in New Issue
Block a user