本帖最后由 yangjiaxu 于 2018-12-24 00:26 编辑
今天早上想要将串口通信移植到电容触摸按键上,但是失败了,在这里想求助一下会玩儿的兄弟。
就是我按照说明是修改了这两处和在主函数上添加了串口打印的代码,但是没有输出出来。
- int main()
- {
- /* Start the SW_Tx_UART Component */
- [color=#ff0000] [b]SW_Tx_UART_Start();[/b][/color]
- #if !ENABLE_TUNER
- /*Used as loop counter and widget ID*/
- uint8 widgetID = 0;
-
- /*Contains the buttons status, one bit per button
- bit0= BTN0 status, bit1 = BTN1 status, bit2 = BTN2 status*/
- uint8 buttonStatus = 0;
- #endif
-
- /* Variable to hold the current device state
- * State machine starts with Sensor_Scan state after power-up
- */
- DEVICE_STATE currentState = SENSOR_SCAN;
-
- /* Enable global interrupts. */
- CyGlobalIntEnable;
- /* Start EZI2C block */
- EZI2C_Start();
- /* Start CapSense block */
- CapSense_Start();
-
- /* Start the TCPWM components, TCPWM1 generates PWM signal of frequency of 100 Hz
- TCPWM2 generates PWM signal of frequency of 101 Hz*/
- TCPWM_1_Start();
- TCPWM_2_Start();
-
- /* Start the SmartIO component, the two PWM signals are XORed to get the
- LED breathing effect of 1 Hz*/
- SmartIO_Start();
-
- #if ENABLE_TUNER
- /* Set up I2C communication data buffer with CapSense data structure
- to be exposed to I2C master on a primary slave address request
- */
- EZI2C_EzI2CSetBuffer1(sizeof(CapSense_dsRam),\
- sizeof(CapSense_dsRam),(uint8 *)&CapSense_dsRam);
- #else
- /*Set up communication data buffer with CapSense slider centroid
- position and button status to be exposed to EZ-BLE Module on CY8CKIT-149 PSoC 4100S Plus Prototyping Kit*/
- EZI2C_EzI2CSetBuffer1(sizeof(i2cBuffer), sizeof(i2cBuffer),i2cBuffer);
- #endif
-
- for(;;)
- {
-
- [color=#ff0000] [b] SW_Tx_UART_PutString("Software Transmit UART");
- SW_Tx_UART_PutString(" Component demo");
- SW_Tx_UART_PutCRLF();[/b][/color] /* Switch between SENSOR_SCAN->WAIT_FOR_SCAN_COMPLETE->PROCESS_DATA states */
- switch(currentState)
- {
- case SENSOR_SCAN:
- /* Initiate new scan only if the CapSense block is idle */
- if(CapSense_NOT_BUSY == CapSense_IsBusy())
- {
- #if ENABLE_TUNER
- /* Update CapSense parameters set via CapSense tuner before the
- beginning of CapSense scan
- */
- CapSense_RunTuner();
- #endif
-
- /* Scan widget configured by CSDSetupWidget API */
- CapSense_ScanAllWidgets();
-
- /* Set next state to WAIT_FOR_SCAN_COMPLETE */
- currentState = WAIT_FOR_SCAN_COMPLETE;
- }
- break;
- case WAIT_FOR_SCAN_COMPLETE:
- /* Put the device to CPU Sleep until CapSense scanning is complete*/
- if(CapSense_NOT_BUSY != CapSense_IsBusy())
- {
- CySysPmSleep();
- }
- /* If CapSense scanning is complete, process the CapSense data */
- else
- {
- currentState = PROCESS_DATA;
- }
- break;
-
- case PROCESS_DATA:
-
- /* Process data on all the enabled widgets */
- CapSense_ProcessAllWidgets();
-
- /* Controls LEDs Status based on the result of Widget processing. */
- LED_Control();
-
- #if !ENABLE_TUNER
-
- /*If tuner is not enabled expose the CapSense slider centroid position and button status to
- EZ-BLE Module on CY8CKIT-149 PSoC 4100S Plus Prototyping Kit via I2C interface*/
-
- /*Update the I2C buffer with slider centroid position*/
- i2cBuffer[SLIDER_CENTROID_INDEX] = (uint8) CapSense_GetCentroidPos(CapSense_SLD_WDGT_ID);
-
- /*Calculate the button status mask and update the I2C buffer
- bit0= BTN0 status, bit1 = BTN1 status, bit2 = BTN2 status*/
- for(widgetID = 0; widgetID < TOTAL_CAPSENSE_BUTTONS ; widgetID++)
- {
- if(CapSense_IsWidgetActive(widgetID))
- {
- SET_BIT(buttonStatus, widgetID);
- }
- else
- {
- CLEAR_BIT(buttonStatus, widgetID);
- }
- }
- i2cBuffer[BUTTON_STATUS_INDEX1] = buttonStatus;
- #endif
-
- /* Set the device state to SENSOR_SCAN */
- currentState = SENSOR_SCAN;
- break;
-
- /*******************************************************************
- * Unknown power mode state. Unexpected situation.
- ******************************************************************/
- default:
- break;
- }
- }
- }
复制代码
我刚刚查到了ADC的实验,串口输出是好用的,我和demo配置的应该一样。
接下来看看我昨天进行的触摸按键实验测试吧。就是在按键上加了一些水,然后测试灵敏度,经测试可以达到我们产品的要求。
接下来请看视频。
此内容由EEWORLD论坛网友yangjiaxu原创,如需转载或用于商业用途需征得作者同意并注明出处