PICマイコン(PIC18F23k22)でMCCを使い、Timer0割込み(200uS毎)の割込みルーチンに、SPIと、Uartを実装しようとしていますが、SPIを割りこみルーチン中に置くと動作しません。main文中ならSPIは動作します。
main()は、下記の記述です。
SYSTEM_Initialize();
TMR0_SetInterruptHandler(inttmr0);
TMR0_StopTimer();
INTERRUPT_GlobalInterruptEnable();
INTERRUPT_PeripheralInterruptEnable();
また、inttmr0の割込みルーチンには、下記を記述しています。
SPI1_WriteByte(0xC0);
while(!SSP1STATbits.BF);
var = SSP1BUF;
EUSART2_Write(0x38);
inttmr0で、EUSART2_Writeだけなら動作しますが、SPI_WriteByteを入れるとEUSART2_Writeも動作しなくなります。Uart動作は、ロジアナ、TeraTermで転送確認しています。
SPIは割込みは使っていないので、inttmr0の最初に、SPI1関連の割込みをマスクしましたが、状況は変わりません。
PIE1bits.SSP1IE = 0;
PIE2bits.BCL1IE = 0;
PIR1bits.SSP1IF = 0;
PICマイコンで、MCCを使った、SPIのタイマー割込みについて、ご教授頂けると助かります。
具体的に、mainのソースを添付します。
/** Generated Main Source File Company: Microchip Technology Inc. File Name: main.c Summary: This is the main file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs Description: This header file provides implementations for driver APIs for all modules selected in the GUI. Generation Information : Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.4 Device : PIC18F23K22 Driver Version : 2.00 */ /* (c) 2018 Microchip Technology Inc. and its subsidiaries. Subject to your compliance with these terms, you may use Microchip software and any derivatives exclusively with Microchip products. It is your responsibility to comply with third party license terms applicable to your use of third party software (including open source software) that may accompany Microchip software. THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. */ #include "mcc_generated_files/mcc.h" #include "L_i2cLCD.h" unsigned char var; unsigned char aa[2]; uint8_t count=0; void inttmr0(void) { #if 1 LATCbits.LATC6 = 0; PIE1bits.SSP1IE = 0; PIE2bits.BCL1IE = 0; PIR1bits.SSP1IF = 0; SPI1_WriteByte(0xC0); while(!SSP1STATbits.BF); var = SSP1BUF; #if 0 SPI1_WriteByte(0x00); while(!SSP1STATbits.BF); var = SSP1BUF; SPI1_WriteByte(0x00); while(!SSP1STATbits.BF); aa[0] = SSP1BUF; SPI1_WriteByte(0x00); while(!SSP1STATbits.BF); aa[1] = SSP1BUF; LATCbits.LATC6 = 1; #endif #endif #if 0 // OK //EUSART2_Write(0x81); // 0729 EUSART2_Write(0x38); // 0729 #endif #if 0 // OK EUSART2_Write(0x30+(count++)); if (count==10) count=0; //printf("now"); #endif } /* Main application */ void main(void) { // Initialize the device SYSTEM_Initialize(); TMR0_SetInterruptHandler(inttmr0); TMR0_StopTimer(); //TMR0_StartTimer(); // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts // Use the following macros to: // Enable the Global Interrupts INTERRUPT_GlobalInterruptEnable(); // Disable the Global Interrupts //INTERRUPT_GlobalInterruptDisable(); // Enable the Peripheral Interrupts INTERRUPT_PeripheralInterruptEnable(); // Disable the Peripheral Interrupts //INTERRUPT_PeripheralInterruptDisable(); #if 0 char msgStart[] ="LCD Disp Test"; LCD_int(); // LCDを初期化 LCD_posyx(0,0); // 下段にカーソル移動 LCD_ROMstr(" iDS8688 sensing"); // 下段に"interface"追記 LCD_posyx(1,0); // 下段にカーソル移動 //LCD_ROMstr("ABCDEFGH="); // 下段に"interface"追記 LCD_dat('N'); // 下段に"I2C "表示 LCD_dat('O'); LCD_dat('W'); #endif TMR0_StartTimer(); while (1) { // Add your application code } } /** End of File */
回答1件
あなたの回答
tips
プレビュー