完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
嗨,我开始用PIC18F26K40工作,我试着在从属模式下运行SPI1接口。我已经使用外围引脚选择(PPS)寄存器来分配SPI1控制线到波尔塔,如下所示。芯片看到SS断言,SCK1时钟和SDI1的数据从主机,但没有活动。在SDO1上没有出现中断。使用调试器,我在SSP1BUF中看不到数据的移动。同一个芯片SPI2被配置为主控器,它是有功能的。还有一个功能UART,它响应于接收中断。我有一个功能类似的PSP18F67 K22配置的SPI从属设备(唯一的区别是丢失的PPS寄存器),我想知道我在这里丢失了什么。下面是我对PIC18F26K40的SPI从机的寄存器设置。有人看到什么问题吗?//启用数字输入ANSELLA=0x00;和/或集成外围输入SSP1DATPPS= 0x02;//RA2作为SDI1 SSP1CKPPS= 0x04;//RA4为SCK1 SSP1SSPPS= 0x05;//RA5为SS1//集成外围输出RA3PPS= 0x10;//RA3为SDO1//启用SPI1端口线LATABItiTS。TSISA5=1;/SS1输入TrISABIIT.TISISA4=1;/SCK1输入TrISABIIT.TISISA3=0;/SDO1输出TrISABIIT.TISISA2=1;//SDI1输入SSP1STAT=0x40;//SET CKE位SSP1CON1= 0x04;//SPI从属模式,SS1控制使能TCNC0=0XE7;/ /允许中断和优先级/ /SPI1中断设置NG IPR3BITS.SSP1IP=0;/低优先级中断PIR3BITS.SSP1IF=0;/ /清除中断标志PY3BITS.SSP1IE=1;//启用中断/启用SPI1接口SSP1CON1BITS SSPEN=1;//中断配置ICONTITION IPEN=1;/ /启用中断优先级ICONTITY。GIHH=1;// EnablE高优先级中断ItCONTITE。GIEL=1;/ /启用低优先级中断谢谢!
以上来自于百度翻译 以下为原文 Hi, I started working with PIC18F26K40 and I'm trying to run the SPI1 interface in Slave mode. I have used the Peripheral Pin Select (PPS) registers to assign the SPI1 control lines to PORTA as shown below. The chip sees SS asserted, SCK1 clock and data on SDI1 from the Master but there is no activity on SDO1 and no interrupt appears. Using the debugger I see no movement of the data in the SSP1BUF. With the same chip SPI2 is configured as Master and it is functional. There is also a functional UART, which is responding to receive interrupt. I have a functional SPI Slave with PIC18F67K22 configured a similar way (the only difference is the missing PPS registers) and I'm wondering what I'm missing here. Below are my register settings for SPI Slave with PIC18F26K40. Does anybody see any issue? // Enable Digital Inputs ANSELA = 0x00; // Integrated Peripheral Inputs SSP1DATPPS = 0x02; // RA2 as SDI1 SSP1CLKPPS = 0x04; // RA4 as SCK1 SSP1SSPPS = 0x05; // RA5 as SS1 // Integrated Peripheral Output RA3PPS = 0x10; // RA3 as SDO1 // Enable SPI1 Port Lines LATAbits.LATA3 = 0; // SDO1 Low TRISAbits.TRISA5 = 1; // SS1 Input TRISAbits.TRISA4 = 1; // SCK1 Input TRISAbits.TRISA3 = 0; // SDO1 Output TRISAbits.TRISA2 = 1; // SDI1 Input SSP1STAT = 0x40; // Set CKE bit SSP1CON1 = 0x04; // SPI Slave Mode, SS1 Control Enabled INTCON = 0xE7; // Enable Interrupts and Priorities // SPI1 Interrupt Setting IPR3bits.SSP1IP = 0; // Low Priority Interrupt PIR3bits.SSP1IF = 0; // Clear the Interrupt Flag PIE3bits.SSP1IE = 1; // Enable the Interrupt // Enable SPI1 Interface SSP1CON1bits.SSPEN = 1; // Interrupt Configuration INTCONbits.IPEN = 1; // Enable Interrupt Priority INTCONbits.GIEH = 1; // Enable High Priority Interrupts INTCONbits.GIEL = 1; // Enable Low Priority Interrupts Thanks! Attached Image(s) |
|
相关推荐
11个回答
|
|
|
|
|
|
|
|
|
中断优先级不是问题。我尝试了具有高优先级中断和不中断的SPI从端口。它是完全死的。有一个分配给POTB的SPI主机和一个在PORTC上的UART,这是完全实用的。整个实现是在一个板上(PCB)。该板上的主MCU通过SPI与单片机进行通信,在使用不同的PIC单片机之前,该功能是可行的。我想我错过了一些小的设置在这里。
以上来自于百度翻译 以下为原文 The interrupt priority is not an issue. I tried the SPI Slave port with high priority interrupts and without interrupts. It is completely dead. There is a SPI Master assigned to PORTB and a UART on PORTC, which are fully functional. The entire implementation is on a board (PCB). The main MCU on this board is supposed to talk with this MCU through SPI. The solution was functional before using a different PIC microcontroller. I guess I'm missing something small with the settings here. |
|
|
|
|
|
向我们展示你的代码的一个小片段并不足以让我们看到“……小东西”的问题。你能发布一个小程序的完整代码来展示这个问题吗?(换句话说,我们不想看到整个你现在的应用程序,但是你应该编写一小部分代码来运行和显示同样的问题。)苏珊
以上来自于百度翻译 以下为原文 Showing us a small snippet of your code is not really enough for us to see any problem with "...something small...". Can you post the complete code of a small app that exhibits the problem? (In other words we don't to see the whole of your current app, but you should write a small bit of code that runs and shows the same problem.) Susan |
|
|
|
|
|
|
|
|
|
|
|
我所发布的是全功能的代码,它可以放在一个主()函数中。只有通过PIC配置寄存器设置振荡器,但不影响代码。这是我目前使用的片段,用PIC18F26K40调试SPI从机的行为。这个代码运行并显示了问题。代码高度简化,甚至SPI中断被拔出。它只初始化PPS(外围PIN选择)寄存器、波尔塔和SPI1外围设备从从属模式。外部SPI主机试图移出在SSP1BUF寄存器中加载的模式。//启用数字输入ANSELLA=0x00;和/或集成外围输入SSP1DATPPS= 0x02;//RA2作为SDI1 SSP1CKPPS= 0x04;//RA4为SCK1 SSP1SSPPS= 0x05;//RA5为SS1//集成外围输出RA3PPS= 0x10;//RA3为SDO1//启用SPI1端口线LATABITITS。TSISA5=1;/SS1输入TrISABIT.TISISA4=1;/SCK1输入TrISABIIT.TISISA3=0;/SDO1输出TrISABIIT.TISISA2=1;//SDI1输入SSP1STAT=0x40;//SET CKE位SSP1CON1= 0x04;//SPI从属模式,SS1控制启用/ /启用SPI1接口SSP1CONBITS.SSPEN=1;/SPI从属输出模式SSP1BUF=0x59;
以上来自于百度翻译 以下为原文 What I have posted is fully functional code, which can be put in a main() function. Only setting the oscillator through the PIC Configuration registers is not included but it doesn't affect the code. This is the snippet I'm currently using it to debug the behavior of the SPI Slave with PIC18F26K40. This code runs and shows the problem. The code is highly simplified, even the SPI interrupt is pulled out. It only initializes the PPS (Peripheral Pin Select) registers, PORTA, and SPI1 peripheral in Slave mode. An external SPI Master is trying to shift out the pattern, which is loaded in the SSP1BUF register. // Enable Digital Inputs ANSELA = 0x00; // Integrated Peripheral Inputs SSP1DATPPS = 0x02; // RA2 as SDI1 SSP1CLKPPS = 0x04; // RA4 as SCK1 SSP1SSPPS = 0x05; // RA5 as SS1 // Integrated Peripheral Output RA3PPS = 0x10; // RA3 as SDO1 // Enable SPI1 Port Lines LATAbits.LATA3 = 0; // SDO1 Low TRISAbits.TRISA5 = 1; // SS1 Input TRISAbits.TRISA4 = 1; // SCK1 Input TRISAbits.TRISA3 = 0; // SDO1 Output TRISAbits.TRISA2 = 1; // SDI1 Input SSP1STAT = 0x40; // Set CKE bit SSP1CON1 = 0x04; // SPI Slave Mode, SS1 Control Enabled // Enable SPI1 Interface SSP1CON1bits.SSPEN = 1; // SPI Slave Out Pattern SSP1BUF = 0x69; |
|
|
|
|
|
“全功能代码”指的是有人可以直接编译并尝试自己。通过不包括配置线或OSCCon设置行,您正在为其他人做更多的工作来尝试您的代码,他们可能会做出不同的假设。这不是获得的方式。人们帮助你。
以上来自于百度翻译 以下为原文 "Fully functional code" means something that someone could compile directly and try themselves. By NOT including the CONFIG lines or OSCCON setting lines, you are making more work for someone else to try your code, with the possibility they will make a different assumption. That is NOT the way to get people to help you. |
|
|
|
|
|
我不确定添加振荡器设置会有什么不同。在我的例子中,我使用的是外部振荡器,而其他人可能更喜欢水晶。无论如何,这是整个项目,因为它出现在我的桌面上。希望这将有助于人们帮助我,这将极大地感谢。/ **************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************H/EC(外部时钟)在8 MHz以上的TraceMac配置文件RSTOSC=ExtOracle 4PLL//EXOSC,每个FEXOSCC位////CONTI1Hα-PracMA配置文件CKOUTEN=O//OSC2 CKOUT功能禁用的“{ PrimaMac配置”CSWEN=OF//NOSC和NDIV位,不可由用户软件α-PrimaMaun-FCMNE=F//故障安全时钟监视器禁用/ ///CON2L L,TraceMaRe= ExtMCLR//RE3 PIN功能是MCR R PraceMac配置,PWRTE=OF//上电定时器禁用,γ-PrAPMA配置,LPBORNEN=OF// Low Power Brown输出复位禁用MA配置PPS1WORE=ON//PPSCOLD位可以被清除并只设置一次PrimaPrimaMac配置STVREN=//堆栈满/欠流导致复位RyPrimaMatlab配置调试=关闭/ /后台调试器禁用了{ PrimaMac配置} XNST=OF//扩展指令集禁用////CONT3Lα-PrAPMA CONFIG WDTCPS= WDTCPS6//看门狗除法器比为1:2048α-PrAPMA配置WSDE=SWDTEN/WDT,由SWDTEN位////CONT3Hα-PracMA配置器WDTCWS=WDTCWS7 7 / /看门狗窗口始终打开(100%)包括/文件/ *******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************将主(空){//能数字输入ANSELLA=0x00;和/或集成外围输入SSP1DATPPS= 0x02;//RA2作为SDI1 SSP1CKPPSS=0x04;//RA4作为SCK1 SSP1SSPPS= 0x05;//RA5作为SS1//集成外围输出RA3PPS= 0x10;//RA3作为SDO1//启用SPI1端口线路LAT;ABTS.LATA3=0;/SDO1低TrISABIT.TISISA5=1;/SS1输入TrISABIIT.TISISA4=1;/SCK1输入TrISABIIT.TISISA3=0;//SDO1输出TrISABIIT.TISISA2=1;//SDI1输入SSP1STAT=0x40;//SET CKE位SSP1CON1= 0x04;//SPI从属模式,SS1控制启用/启用SPI1接口SSP1CONBIT位。SSPEN=1;/SPI从属模式SSP1BUF=0x59;/ /等待SPI主活动,而(1){//测试语句/ /。…} / /结束“主体”()
以上来自于百度翻译 以下为原文 I'm not sure that adding the oscillator settings will make any difference. In my case I'm using an external oscillator, while somebody else could prefer a crystal. Anyway here is the entire project as it appears on my desktop. Hope this will facilitate people to help me, which will be greatly appreciated. //****************************************************************************** // PIC CONFIG SETTINGS //****************************************************************************** // CONFIG1L #pragma config FEXTOSC = ECH // EC (External Clock) above 8 MHz #pragma config RSTOSC = EXTOSC_4PLL // EXTOSC with 4x PLL Operating per FEXTOSC bits // // CONFIG1H #pragma config CLKOUTEN = OFF // OSC2 CLKOUT Function Disabled #pragma config CSWEN = OFF // NOSC and NDIV Bits Not Changable by User Software #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Disabled // // CONFIG2L #pragma config MCLRE = EXTMCLR // RE3 Pin Function is MCLR #pragma config PWRTE = OFF // Power Up Timer Disabled #pragma config LPBOREN = OFF // Low-Power Brown-out Reset Disabled #pragma config BOREN = OFF // Brown-out Reset Disabled // // CONFIG2H #pragma config PPS1WAY = ON // PPSLOCK Bit can be Cleared and Set Only Once #pragma config STVREN = ON // Stack Full/Underflow Cause Reset #pragma config DEBUG = OFF // Background Debugger Disabled #pragma config XINST = OFF // Extended Instruction Set Disabled // // CONFIG3L #pragma config WDTCPS = WDTCPS_6 // Watchdog Divider Ratio 1:2048 #pragma config WDTE = SWDTEN // WDT Enabled/Disabled by SWDTEN Bit // // CONFIG3H #pragma config WDTCWS = WDTCWS_7 // Watchdog Window Always Open (100%) #pragma config WDTCCS = SC // Watchdog Timer Software Control //****************************************************************************** // INCLUDE FILES //****************************************************************************** #include //****************************************************************************** //Function: main() //****************************************************************************** void main(void) { // Enable Digital Inputs ANSELA = 0x00; // Integrated Peripheral Inputs SSP1DATPPS = 0x02; // RA2 as SDI1 SSP1CLKPPS = 0x04; // RA4 as SCK1 SSP1SSPPS = 0x05; // RA5 as SS1 // Integrated Peripheral Output RA3PPS = 0x10; // RA3 as SDO1 // Enable SPI1 Port Lines LATAbits.LATA3 = 0; // SDO1 Low TRISAbits.TRISA5 = 1; // SS1 Input TRISAbits.TRISA4 = 1; // SCK1 Input TRISAbits.TRISA3 = 0; // SDO1 Output TRISAbits.TRISA2 = 1; // SDI1 Input SSP1STAT = 0x40; // Set CKE bit SSP1CON1 = 0x04; // SPI Slave Mode, SS1 Control Enabled // Enable SPI1 Interface SSP1CON1bits.SSPEN = 1; // SPI Slave Out Pattern SSP1BUF = 0x69; // Waiting for SPI Master Activity while (1) { // Test Statements // . . . } } // End of 'main()' |
|
|
|
|
|
对于任何测试目的,最好在while循环中放置一个“发送代码”。(也可能检查国旗)
以上来自于百度翻译 以下为原文 For any testing purpose, better place a "sending code" inside the while loop. (check the flags too, possibly) |
|
|
|
|
|
你的意思是什么?代码只是初始化I/O端口、SSP和SPI(集成外围设备)作为SPI Slave。此时,SPI从属设备的硬件独立地等待来自主机的SS断言和SCK。
以上来自于百度翻译 以下为原文 Which flags do you mean? The code is just initializing the I/O Port, SSP and SPI (integrated peripheral) as SPI Slave. At this point the hardware of the SPI Slave is independently waiting for SS assertion and SCK from a Master. |
|
|
|
|
|
我的意思是缓冲区满了,可能还有OVF。不确定这是否适用于你的照片
以上来自于百度翻译 以下为原文 The buffer-full and possibly OVF, I meant. Not sure if this applies to your PIC too |
|
|
|
|
|
你是对的。使用ICD-3调试器,我在while(1){}循环的主体中设置测试语句,但是在当前设置中,SPI主控器将通过SDO1线移出SSP1BUF中发现的模式。
以上来自于百度翻译 以下为原文 You are right. Using the ICD-3 debugger I'm setting test statements in the body of the while (1) {} loop. But with the current setup the SPI Master is expected to shift out the pattern found in SSP1BUF through the SDO1 line. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1123浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 01:02 , Processed in 1.219856 second(s), Total 90, Slave 73 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1552