CH432INT#中斷問題

目前使用STM32+CH432,可以收發(fā),但在設(shè)置INT#中斷為外部輸入中斷后,即使兩個串口有信息回復(fù),也無法觸發(fā)INT#中斷,如果把void CH432Interrupt(void)?函數(shù)放在進(jìn)程中輪詢,INT#中斷才會觸發(fā),但是正常流程應(yīng)該是把CH432Interrupt(void)函數(shù)放在INT#中斷服務(wù)函數(shù)里執(zhí)行,請問可能是什么原因?

配置如下:

???UINT16?div;
????UINT8?DLL,?DLM;
/**************************************************************************
??????????設(shè)置CH432串口0的寄存器
**************************************************************************/
????div?=?(?Fpclk?>>?4?)?/?CH432_BPS0;
????DLM?=?div?>>?8;
????DLL?=?div?&?0xff;
????WriteCH432Data(?CH432_IER_PORT,?BIT_IER_RESET);??//端口復(fù)位//
????WriteCH432Data(?CH432_LCR_PORT,?BIT_LCR_DLAB?);????/*?設(shè)置DLAB為1?*/
????WriteCH432Data(?CH432_DLL_PORT,?DLL?);????/*?設(shè)置波特率?*/
????WriteCH432Data(?CH432_DLM_PORT,?DLM?);
????WriteCH432Data(?CH432_FCR_PORT,?BIT_FCR_FIFOEN?);????/*?設(shè)置FIFO模式,觸發(fā)點(diǎn)為14?*/
????WriteCH432Data(?CH432_LCR_PORT,?BIT_LCR_WORDSZ1?|?BIT_LCR_WORDSZ0?);????/*?字長8位,1位停止位、無校驗(yàn)?*/
????WriteCH432Data(?CH432_IER_PORT,?BIT_IER_IEMODEM?|?BIT_IER_IELINES?|?BIT_IER_IETHRE?|?BIT_IER_IERECV?);????/*?使能中斷?*/
????WriteCH432Data(?CH432_MCR_PORT,?BIT_MCR_OUT2);????/*?允許中斷輸出,DTR,RTS為1?*/
/**************************************************************************
??????????設(shè)置CH432串口1的寄存器
**************************************************************************/
????div?=?(?Fpclk?>>?4?)?/?CH432_BPS1;
????DLM?=?div?>>?8;
????DLL?=?div?&?0xff;
????WriteCH432Data(?CH432_IER1_PORT,?BIT_IER_RESET);??//端口復(fù)位//
????WriteCH432Data(?CH432_LCR1_PORT,?BIT_LCR_DLAB?);????/*?設(shè)置DLAB為1?*/
????WriteCH432Data(?CH432_DLL1_PORT,?DLL?);????/*?設(shè)置波特率?*/
????WriteCH432Data(?CH432_DLM1_PORT,?DLM?);
????WriteCH432Data(?CH432_FCR1_PORT,?BIT_FCR_FIFOEN?);????/*?設(shè)置FIFO模式,觸發(fā)點(diǎn)為14?*/
????WriteCH432Data(?CH432_LCR1_PORT,?BIT_LCR_WORDSZ1?|?BIT_LCR_WORDSZ0?);????/*?字長8位,1位停止位、無校驗(yàn)?*/
????WriteCH432Data(?CH432_IER1_PORT,?BIT_IER_IEMODEM?|?BIT_IER_IELINES?|?BIT_IER_IETHRE?|?BIT_IER_IERECV?);????/*?使能中斷?*/
????WriteCH432Data(?CH432_MCR1_PORT,?BIT_MCR_OUT2);????/*?允許中斷輸出,DTR,RTS為1?*/


您好,這個初始化沒有什么問題。

可以在接收數(shù)據(jù)時,查看CH432的INT#引腳是否會輸出低電平,若有輸出低電平,則可能是單片機(jī)沒有抓到中斷,可以檢查一下單片機(jī)中斷配置是否正確,CH432的中斷是低電平有效,所以GPIO應(yīng)該設(shè)置為上拉輸入,中斷是下降沿觸發(fā)。


您好,INT#管腳需要外部加上拉電阻嗎


如果正確設(shè)置IO的話,是不需要外接上拉電阻的


你好,最近沒處理這個問題,目前測試,單片機(jī)外部中斷輸入脈沖是可以觸發(fā)的,432芯片的INT#管腳沒有輸出下降沿,一直是低電平


IER:00?

IIR1:01?

IIR:01?

FCR:01?

MCR:00?

LSR:60?

MSR:00



您好,低電平應(yīng)該是有中斷產(chǎn)生才對。CH432在產(chǎn)生中斷后根據(jù)不同的中斷類型,需要讀取相應(yīng)的寄存器才會清除中斷,如果一直是低電平,則說明中斷沒有清除,可以檢查一下中斷服務(wù)函數(shù)是否有清除中斷。

下面的代碼是對引腳PB10的設(shè)置,以及中斷服務(wù)函數(shù),其他代碼部分可以參考CH432EVT提供的例程

void?INT_Init(void)??????//***初始化INT#**//
{
	GPIO_InitTypeDef?GPIO_InitStructure;
	EXTI_InitTypeDef?EXTI_InitStructure;
	NVIC_InitTypeDef?NVIC_InitStructure;
	
	RCC_APB2PeriphClockCmd(	RCC_APB2Periph_GPIOB,?ENABLE?);	
????RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);	
	
	//-------------------------------------------
	GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_10;
	GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IPU?;???//上拉輸入	
	GPIO_Init(GPIOB,?&GPIO_InitStructure);	
	
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,?GPIO_PinSource10);??
????/*?Configure?Button?EXTI?line?*/
????EXTI_InitStructure.EXTI_Line?=?EXTI_Line10;
????EXTI_InitStructure.EXTI_Mode?=?EXTI_Mode_Interrupt;
????EXTI_InitStructure.EXTI_Trigger?=?EXTI_Trigger_Falling;??
????EXTI_InitStructure.EXTI_LineCmd?=?ENABLE;
????EXTI_Init(&EXTI_InitStructure);

	/*?Enable?the?EXTI?Interrupt?*/
	NVIC_InitStructure.NVIC_IRQChannel?=?EXTI15_10_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority?=?0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?1;
	NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE;
	NVIC_Init(&NVIC_InitStructure);
	//--------------------------------------
}
void?EXTI15_10_IRQHandler(void)
{
	EXTI_ClearITPendingBit(EXTI_Line10);?//清空中斷標(biāo)志位,防止持續(xù)進(jìn)入中斷??	
????UartDetectInterrupt(?);
}
UINT8?UartDetectInterrupt(?)????/*?查詢CH432的中斷狀態(tài)?*/
{
????UINT8?InterruptStatus;
????UINT8?RcvNum?=?0;
????UINT8?s,i;
????UINT8?ModemStatus;
????while(?1?)
????{
????????InterruptStatus?=?ReadCH432Data(?CH432_IIR_PORT?)&?(?~?CH432_IIR_FIFOS_ENABLED?);
????????if(?(?InterruptStatus?&?0x01?)?)????/*?沒有中斷轉(zhuǎn)到串口1?*/
????????{
????????????InterruptStatus?=?ReadCH432Data(?CH432_IIR1_PORT)?&?(?~?CH432_IIR_FIFOS_ENABLED?);????/*?讀串口1的中斷狀態(tài)?*/
????????????if(?(?InterruptStatus?&?0x01?)?)?break;????/*?沒有中斷退出?*/
????????????else
????????????{
????????????????switch(?InterruptStatus?)
????????????????{
????????????????????case?INT_NOINT:????/*?沒有中斷?*/
????????????????????????break;
????????????????????case?INT_THR_EMPTY:????/*?發(fā)送保持寄存器空中斷?*/
????????????????????????break;
????????????????????case?INT_RCV_SUCCESS:????/*?串口接收可用數(shù)據(jù)中斷?*/
????????????????????????RcvNum?=?CH432Seril1Rcv(?buf?);
					????buf[RcvNum]=0;
					????printf("%s",?buf?);
//					????CH432Seril0Send(?buf,?RcvNum?);
????????????????????????break;
????????????????????case?INT_RCV_LINES:????/*?接收線路狀態(tài)中斷?*/
?????????????????????????ReadCH432Data(?CH432_LSR1_PORT);
????????????????????????break;
????????????????????case?INT_RCV_OVERTIME:????/*?接收數(shù)據(jù)超時中斷?*/
????????????????????????RcvNum?=?CH432Seril1Rcv(?buf?);
					????buf[RcvNum]=0;
					????printf("%s",?buf?);
//????????????????????????CH432Seril1Send(?buf,?RcvNum?);
????????????????????????break;
????????????????????default:????/*?不可能發(fā)生的中斷?*/
????????????????????????break;
????????????????}
????????????}
????????}?
????????else
????????{
????????????switch(?InterruptStatus?)
????????????{
????????????????case?INT_NOINT:????/*?沒有中斷?*/
????????????????????break;
????????????????case?INT_THR_EMPTY:????/*?發(fā)送保持寄存器空中斷?*/
????????????????????break;
????????????????case?INT_RCV_SUCCESS:????/*?串口接收可用數(shù)據(jù)中斷?*/
????????????????????RcvNum?=?CH432Seril0Rcv(?buf?);
					buf[RcvNum]=0;
					printf("%s",?buf?);
//????????????????????UART0_SendByte(?RcvNum?);
//????????????????????CH432Seril0Send(?buf,?RcvNum?);
????????????????????break;
????????????????case?INT_RCV_LINES?:????/*?接收線路狀態(tài)中斷?*/
????????????????????ReadCH432Data(?CH432_LSR_PORT);
????????????????????break;
????????????????case?INT_RCV_OVERTIME:????/*?接收數(shù)據(jù)超時中斷?*/
????????????????????RcvNum?=?CH432Seril0Rcv(?buf?);
					buf[RcvNum]=0;
					printf("%s",?buf?);
//????????????????????UART0_SendByte(?RcvNum?);
//????????????????????CH432Seril0Send(?buf,?RcvNum?);
????????????????????break;
????????????????default:????/*?不可能發(fā)生的中斷?*/
????????????????????break;
????????????}
????????}
????}
????return(?InterruptStatus?);
}




目前發(fā)現(xiàn)下面的配置通訊是比較穩(wěn)定的,BIT_IER_IETHRE?中斷必須屏蔽,否則無法接收,請問是什么原因
void?InitCH432(?void?)????/*?初始化CH432?*/
{
????UINT16?div;
????UINT8?DLL,?DLM;
/**************************************************************************
??????????設(shè)置CH432串口0的寄存器

**************************************************************************/
????div?=?(?Fpclk?>>?4?)?/?CH432_BPS0;
????DLM?=?div?>>?8;
????DLL?=?div?&?0xff;
????WriteCH432Data(?CH432_IER_PORT,?BIT_IER_RESET);??//端口復(fù)位//
????WriteCH432Data(?CH432_LCR_PORT,?BIT_LCR_DLAB?);????/*?設(shè)置DLAB為1?*/
????WriteCH432Data(?CH432_DLL_PORT,?DLL?);????/*?設(shè)置波特率?*/
????WriteCH432Data(?CH432_DLM_PORT,?DLM?);
????WriteCH432Data(?CH432_FCR_PORT,?BIT_FCR_RECVTG1?|?BIT_FCR_RECVTG0?|?BIT_FCR_FIFOEN?);????/*?設(shè)置FIFO模式,觸發(fā)點(diǎn)為14?*/
????WriteCH432Data(?CH432_LCR_PORT,?BIT_LCR_WORDSZ1?|?BIT_LCR_WORDSZ0?);????/*?字長8位,1位停止位、無校驗(yàn)?*/
????WriteCH432Data(?CH432_IER_PORT,?BIT_IER_IEMODEM?|?BIT_IER_IELINES?|?/*BIT_IER_IETHRE?|*/?BIT_IER_IERECV);????/*?使能中斷?*/
????WriteCH432Data(?CH432_MCR_PORT,?BIT_MCR_OUT2);????/*?允許中斷輸出,DTR,RTS為1?*/

/**************************************************************************
??????????設(shè)置CH432串口1的寄存器

**************************************************************************/
????div?=?(?Fpclk?>>?4?)?/?CH432_BPS1;
????DLM?=?div?>>?8;
????DLL?=?div?&?0xff;
????WriteCH432Data(?CH432_IER1_PORT,?BIT_IER_RESET);??//端口復(fù)位//
????WriteCH432Data(?CH432_LCR1_PORT,?BIT_LCR_DLAB?);????/*?設(shè)置DLAB為1?*/
????WriteCH432Data(?CH432_DLL1_PORT,?DLL?);????/*?設(shè)置波特率?*/
????WriteCH432Data(?CH432_DLM1_PORT,?DLM?);
????WriteCH432Data(?CH432_FCR1_PORT,?BIT_FCR_RECVTG1?|?BIT_FCR_RECVTG0?|?BIT_FCR_FIFOEN?);????/*?設(shè)置FIFO模式,觸發(fā)點(diǎn)為14?*/
????WriteCH432Data(?CH432_LCR1_PORT,?BIT_LCR_WORDSZ1?|?BIT_LCR_WORDSZ0?);????/*?字長8位,1位停止位、無校驗(yàn)?*/
????WriteCH432Data(?CH432_IER1_PORT,?BIT_IER_IEMODEM?|?BIT_IER_IELINES?|?/*BIT_IER_IETHRE?|*/?BIT_IER_IERECV);????/*?使能中斷?*/
????WriteCH432Data(?CH432_MCR1_PORT,?BIT_MCR_OUT2);????/*?允許中斷輸出,DTR,RTS為1?*/

}



您好:

THR中斷是“發(fā)送保持寄存器空”中斷,當(dāng)您的THR寄存器空時會產(chǎn)生該中斷。如果當(dāng)您開啟這個中斷卻導(dǎo)致無法接收數(shù)據(jù),您可以檢查INT引腳是否為低電平,若INT引腳為低電平則說明有中斷沒有清除,可以查詢IIR 寄存器以判斷相應(yīng)中斷并清除中斷。


目前來看,開啟的狀態(tài)下,則無法產(chǎn)生中斷,屏蔽狀態(tài)下,就可以產(chǎn)生中斷,測試久了也不穩(wěn)定,中斷函數(shù)如下:

UINT8?CH432Interrupt(void)??/*?中斷方式處理?*/
{
????UINT8?InterruptStatus;
????UINT8?RcvNum?=?0,?i;
????while(1)
????{
????????InterruptStatus?=?ReadCH432Data(?CH432_IIR_PORT?)?&?(?~?CH432_IIR_FIFOS_ENABLED?);
????????if(?(?InterruptStatus?&?0x01?)?)????/*?沒有中斷轉(zhuǎn)到串口1?*/
????????{}
????????else
????????{
????????	switch(?InterruptStatus?)
????????????{
????????????????case?INT_NOINT:????/*?沒有中斷?*/
????????????????????????break;
????????????????case?INT_THR_EMPTY:????/*?發(fā)送保持寄存器空中斷?*/
????????????????		printf("INT_THR_EMPTY\r\n");
????????????????????????break;
????????????????case?INT_RCV_SUCCESS:????/*?串口接收可用數(shù)據(jù)中斷?*/
????????????????????????RcvNum?=?CH432Seril0Rcv(?uart_dma_rx_buf3?);
????????????????????????break;
????????????????case?INT_RCV_LINES:????/*?接收線路狀態(tài)中斷?*/
????????????????????????ReadCH432Data(?CH432_LSR_PORT);
????????????????????????break;
????????????????case?INT_RCV_OVERTIME:????/*?接收數(shù)據(jù)超時中斷?*/
????????????????????????RcvNum?=?CH432Seril0Rcv(?uart_dma_rx_buf3?);
????????????????????????break;
????????????????default:????/*?不可能發(fā)生的中斷?*/
????????????????????????break;
????????????}
????????}

????????InterruptStatus?=?ReadCH432Data(?CH432_IIR1_PORT?)?&?(?~?CH432_IIR_FIFOS_ENABLED?);????/*?讀串口1的中斷狀態(tài)?*/
????????if(?(?InterruptStatus?&?0x01?)?)???break;??/*?沒有中斷退出?*/
????????else
????????{
????????????switch(?InterruptStatus?)
????????????{
????????????????case?INT_NOINT:????/*?沒有中斷?*/
????????????????????break;
????????????????case?INT_THR_EMPTY:????/*?發(fā)送保持寄存器空中斷?*/
????????????????	printf("INT_THR1_EMPTY\r\n");
????????????????????break;
????????????????case?INT_RCV_SUCCESS:????/*?串口接收可用數(shù)據(jù)中斷?*/
????????????????????RcvNum?=?CH432Seril1Rcv(uart_dma_rx_buf4);
????????????????????break;
????????????????case?INT_RCV_LINES:????/*?接收線路狀態(tài)中斷?*/
????????????????????ReadCH432Data(?CH432_LSR1_PORT);
????????????????????break;
????????????????case?INT_RCV_OVERTIME:????/*?接收數(shù)據(jù)超時中斷?*/
????????????????????RcvNum?=?CH432Seril1Rcv(uart_dma_rx_buf4);
????????????????????break;
????????????????default:????/*?不可能發(fā)生的中斷?*/
????????????????????break;
????????????}
????????}
????}
????return(?InterruptStatus?);
}



屏蔽BIT_IER_IETHRE中斷,是否會導(dǎo)致接收不穩(wěn)定的情況


您好:

屏蔽BIT_IER_IETHRE中斷是可以正常收發(fā)數(shù)據(jù)的,發(fā)送數(shù)據(jù)是由您主動發(fā)起,可以不用開啟發(fā)送寄存器空中斷,不會造成不穩(wěn)定的情況


我現(xiàn)在的情況,就是只有屏蔽BIT_IER_IETHRE才能正常接收數(shù)據(jù),不屏蔽就產(chǎn)生了一次INT_THR_EMPTY中斷,就無法再進(jìn)入中斷了,請問這可能是什么原因?qū)е碌?/p>


您好:

在初始化結(jié)束后,您可以先檢查一下各個寄存器寫入的值是否正確,如果配置的值和預(yù)想的值不一樣的話,可能是以下原因。

IETHR由0到1時會產(chǎn)生一個INT_THR_EMPTY中斷。在初始化時,您先是寫了一個“IETHR由0到1”從而產(chǎn)生了一個INT_THR_EMPTY中斷,而在后續(xù)的打開MCR寄存器的OUT2位時,相當(dāng)于允許了串口的中斷輸出,使INT#引腳拉低,進(jìn)入中斷服務(wù)函數(shù),在這個過程中,可能導(dǎo)致您的某些寄存器的配置出現(xiàn)錯誤。

解決方法有:

1.SPI的接口函數(shù)要按照以下格式(推薦該方法)。

接口函數(shù)()

{

? ?SCS拉高? ? //避免某些情況(如中斷)導(dǎo)致的SCS狀態(tài)不正常,從而影響到后續(xù)的數(shù)據(jù)寫入

? ?SCS拉低

? ?輸入數(shù)據(jù)

? ?SCS拉高

}

2.在初始化CH432后,再開啟中斷,并在開啟中斷后讀CH432的中斷類型清中斷。



#define?CH432_BPS0?230400????/*?定義CH432串口0通訊波特率?*/
#define?CH432_BPS1?230400????/*?定義CH432串口1通訊波特率?*/
#define?Fpclk??????(1843200)?//1843200????/*?定義內(nèi)部時鐘頻率????*/
如何設(shè)置CH432的波特率未230400,外部晶振22.1184MHz



您好

波特率的設(shè)置公式是:所需通訊波特率 =?串口內(nèi)部基準(zhǔn)時鐘 / 16 / DLL和DLM寄存器值

其中串口內(nèi)部基準(zhǔn)時鐘由晶振以及內(nèi)部倍頻決定。由下表可知,當(dāng)使用22.1184MHz晶振,內(nèi)部2倍頻時,最大波特率為2.7648Mbps。

image.png


即,所需配置為

  1. 先配置CK2X位為1,使用內(nèi)部2倍頻,此時的內(nèi)部基準(zhǔn)時鐘為44.2368MHz。

  2. 根據(jù)公式代入所需230400的波特率,可以得出DLL和DLM寄存器的值為12,所以配置DLL的值為0x0C,DLM的值為0x00。


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频