完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,从PIC24FJ128GA308,我尝试使用引脚:-RG6(RP21)作为SCK1输出-RG7(RP26)作为SDI1输入-RG8(RP19)作为SDO1 OutPurthOver,SCK1不计时。Sdo1的输出工作很好。初始化是通过写给SPI的代码完成的:在循环这个例程时增加了“值”,我看到SDO输出递增,但是没有SDKSB输出SK1到RP21的SCKSWACK SCK1,但是在RP19上仍然没有时钟。一个初始化“SOWWeY”,但是在哪里?
以上来自于百度翻译 以下为原文 Hi, From the PIC24FJ128GA308 I try to use the pins: - RG6 (RP21) as the SCK1 output - RG7 (RP26) as the SDI1 input - RG8 (RP19) as the SDO1 output However, the SCK1 doesn't clock. The SDO1 output works fine. Initializing is done by: TRISG=0b1111111010111111; // // Unlock Registers asm volatile( "MOV #OSCCON, w1 n" "MOV #0x46, w2 n" "MOV #0x57, w3 n" "MOV.b w2, [w1] n" "MOV.b w3, [w1] n" "BCLR OSCCON,#6") ; // or use C30 built-in macro: // __builtin_write_OSCCONL(OSCCON & 0xbf); // Configure Input Functions (Table 11-2)) RPINR20bits.SDI1R = 26; // assign SDI1 to RP26 RPOR9bits.RP19R = 7; // assign SDO1 to RP19 RPOR10bits.RP21R = 8; // assign SCK1 to RP21 // Lock Registers asm volatile ("MOV #OSCCON, w1 n" "MOV #0x46, w2 n" "MOV #0x57, w3 n" "MOV.b w2, [w1]n" "MOV.b w3, [w1]n" "BSET OSCCON, #6") ; // or use C30 built-in macro: // __builtin_write_OSCCONL(OSCCON | 0x40); /* Initialize peripherals */ CM1CON=0x0000; ANSA=0x0000; ANSB=0x000F; ANSD=0x0000; ANSD=0x0000; ANSG=0x0000; /* initialize SPI1 */ SPI1STAT=0x0000; SPI1CON1=0b0001000000111011; SPI1CON2=0x0000; SPI1STATbits.SPIEN = 1; //enable SPI mode The code that writes to the SPI: void DAC(unsigned char channel, unsigned int value) { unsigned char Bh=0; unsigned char Bl=0; Bh=0x03 | (value>>6); Bl=(value & 0x003F) << 2; DAC_CS=DAC_SC_SELECT; SPI1BUF=Bh; while(SPI1STATbits.SPITBF); SPI1BUF=Bl; while(SPI1STATbits.SPITBF); DAC_CS=DAC_SC_IDLE; __delay_us(1); DAC_LDAC=DAC_LDAC_LOAD; __delay_us(1); DAC_LDAC=DAC_LDAC_IDLE; } When looping this routine with incrementing 'value' I see the SDO output incrementing, but there is no SCK Swapping SCK1 with SDO1 by RPOR9bits.RP19R = 8; // assign SCK1 to RP19 RPOR10bits.RP21R = 7; // assign SDO1 to RP21 Outputs SDO1 to RP21, but then there is still no clock on RP19. Probably I'm missing an initialisation 'somwehere' but where? |
|
相关推荐
3个回答
|
|
您已经设置了SSP1CON(DISSCK)的位×12,它禁用SCK引脚。
以上来自于百度翻译 以下为原文 You have set bit#12 of SSP1CON (DISSCK), which disables the SCK pin. |
|
|
|
是的,这是一个初始化错误…我自己初始化了SPI1CON错误:比特12(DISCK)应该是0…但是我应该写:
以上来自于百度翻译 以下为原文 Yes, it was an initialisation error... by myself. I initialized the SPI1CON wrong with: SPI1CON1=0b0001000000111011; bit 12 (DISSCK) should been 0 however... I should have written: SPI1CON1bits.PPRE=3; SPI1CON1bits.SPRE=6; SPI1CON1bits.MSTEN=1; SPI1CON1bits.CKP=0; SPI1CON1bits.SSEN=0; SPI1CON1bits.CKE=0; SPI1CON1bits.SMP=1; SPI1CON1bits.MODE16=0; SPI1CON1bits.DISSDO=0; SPI1CON1bits.DISSCK=0; |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5046 浏览 9 评论
1938 浏览 8 评论
1874 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3092 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2160 浏览 5 评论
601浏览 1评论
468浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
497浏览 0评论
402浏览 0评论
IPECMD命令烧录AVR128DA48芯片,报找不到芯片错误
878浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-9-8 20:24 , Processed in 0.982506 second(s), Total 51, Slave 44 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191