• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::

論壇索引


Board index » All Posts (C_H_M)




Re: 關於Halting build on first failure as requested.
#1
中級會員
中級會員


你好!

你目前問題的主要原因是因為你所使用的 c30 版本太舊,
無法支援到你的 pic24F 元件所致.

請先下載新版的 c30 再試試吧!

發表於: 2009/1/9 8:50
頂部


Re: 請教 30F2020的SPI問題
#2
中級會員
中級會員


是的, 沒有錯!

即使有些間隔的時間存在, 還是會被當成連續的資料被接收.
不會有任何問題的.

事實上 SPI 可以說根本是以 CK 有無變化為準的.
不但可以有像這樣的間隔時間不會有問題, 即使 CK 並不是等寬的方波也不會有問題發生.
大概只有 CK 的最高速率, HI / LO 的最小維持時間真的需要注意!

發表於: 2008/12/26 20:29
頂部


Re: 請教 30F2020的SPI問題
#3
中級會員
中級會員


在以下這裡會造成問題.

/*設置SPI中斷*/
IFS0bits.SPI1IF = 0 ; //未產生中斷
IEC0bits.SPI1IE = 1 ; //允許中斷
IPC2bits.SPI1IP = 4 ; //中斷優先權 = 4

-----------------------------------------------

因為在你的程式中很明顯的並未使用 spi 中斷程序,
所以如果你開啟了中斷致能會使得 MCU 進入 SPI 中斷裡面,
導致錯誤發生, 應該改為不致能進入 SPI 中斷程序.

/*設置SPI中斷*/
IFS0bits.SPI1IF = 0 ; //未產生中斷
IEC0bits.SPI1IE = 0 ; //不致能進入中斷處理程序
IPC2bits.SPI1IP = 4 ; //中斷優先權 = 4

發表於: 2008/12/26 7:04
頂部


Re: 請教 30F2020的SPI問題
#4
中級會員
中級會員


你好! 還有問題的話請你試試如下:

-------------------------------------------------------------------------------------
int spi_char;



cs = low;
_SPI1IF = 0;

SPI1BUF = 0X02 ; //先傳指令
while(_SPI1IF == 0);
_SPI1IF = 0; // 清除 SPI 中斷旗號
spi_char = SPI1BUF;

SPI1BUF = 0X01 ; //再傳address
while(_SPI1IF == 0);
_SPI1IF = 0; // 清除 SPI 中斷旗號
spi_char = SPI1BUF;

SPI1BUF = 0X33 ; //最後是data
while(_SPI1IF == 0); //
_SPI1IF = 0; // 清除 SPI 中斷旗號
spi_char = SPI1BUF;

cs = hi;
-------------------------------------------------------------------------------------
加上這個讀取動作, 這是因為 dspic30F 的 spi 是一個雙向動作的模組,
如果沒有讀出的動作時, 會有讀入資料溢位的錯誤產生,
或許是讀入資料的溢位錯誤導致新的資料輸出無動作吧!

發表於: 2008/12/25 22:21
頂部


Re: 請教 30F2020的SPI問題
#5
中級會員
中級會員


你好! 你現在的程式中有個不太對的地方,

if (!SPI1STATbits.SPITBF); //再次確定已傳送出去

在這裡應該使用 while(SPI1STATbits.SPITBF);
因為 SPI 的傳送動作是需要時間的, 以你的原方式則不會等待到 SPI 資料傳遞到 SPIxSR.

-------------------------------------------------------------------------------------
cs = low;

SPI1BUF = 0X02 ; //先傳指令

while(SPI1STATbits.SPITBF); // 若 SPITBF == 1表示未傳出, 需等待

SPI1BUF = 0X01 ; //再傳address

while(SPI1STATbits.SPITBF); // 若 SPITBF == 1表示未傳出, 需等待

SPI1BUF = 0X33 ; //最後是data

while(SPI1STATbits.SPITBF); // 若 SPITBF == 1表示未傳出, 需等待

cs = hi;

-------------------------------------------------------------------------------------
另外, 當 SPI 以 master 模式使用時, 在 SPI 傳送結束時會產生中斷旗號 (_SPI1IF = 1)
可以判斷 _SPI1IF 來知道 SPI 傳送是否要結束了, 或是要接著傳下一個資料出去.

cs = low;
_SPI1IF = 0;

SPI1BUF = 0X02 ; //先傳指令
while(_SPI1IF == 0);
_SPI1IF = 0; // 清除 SPI 中斷旗號

SPI1BUF = 0X01 ; //再傳address
while(_SPI1IF == 0); //

SPI1BUF = 0X33 ; //最後是data
while(_SPI1IF == 0); //
_SPI1IF = 0; // 清除 SPI 中斷旗號

cs = hi;
-------------------------------------------------------------------------------------
GOOD LUCK !!!!!

發表於: 2008/12/25 11:10
頂部


Re: i/o模擬uart 傳接收
#6
中級會員
中級會員


你好!

突然發現你的程式很明顯少了 start bit 的部分.
建議你加上 start bit 在實際的傳送資料前面, 再試一下吧!

#include <p18f4620.h>
#define tx PORTCbits.RC3 

void Delay(unsigned long int t)
{
unsigned long int i;
for(
i=0;i<=t;i++);
}

void main(void)

unsigned int SD,cnt,i=0;
TRISC=0x02;
tx 1;
while(
1)
     {
     
SD=0x55;

[
color=CC0000]     // 在這裡加上 start bit, 大概是像以下這兩行
     // *** tx = 0;
     // *** Delay(k);[/color]
     
for(cnt=0;cnt<8;cnt++)
       {
       
tx=SD%2;
       
SD=SD/2;
       
Delay(1); 
       
Nop();Nop();Nop();Nop(); 
       }
     
tx 1;
     
Delay(1000);
     }
}


正確的 0x55 傳送順序     start bit,   bit0,      bit1,     bit2,   bit3,   bit4,   bit5,   bit6,   bit7,   stop bit
                             0         1          0         1       0       1       0       1       0         1

少1個 start bit 後的錯誤   
---       ---    錯誤的start     1       0       1       0       1       0         1        1    stop 0xD5

發表於: 2008/11/25 23:34
頂部


Re: UART問題
#7
中級會員
中級會員


你好!

你所提的是像 dsPIC30F4011 這種其中有 UART_ALTRX_ALTTX 的,

這是用來選擇 UART1 的 TX RX I/O 腳位置的,
dsPIC30F4011 的 TX RX 是有兩處配置可供選擇來使用的,
除了 RF3/U1TX, RF2/U1RX 的 I/O 位置外,
另外還有 RC13/U1ATX, RC14/U1ARX 的 I/O 位置,
當設定 UART1 為 UART_ALTRX_ALTTX 表示使用 U1ATX/U1ARX 的 I/O 位置,
如果設定 UART1 為 UART_RX_TX 則使用 U1TX/U1RX 的 I/O 位置,

但是請注意要使用 ICD2 這類工具時, U1TX/U1RX 會與 PGD/PGC 的 I/O 位置相同喔!
這個時候應該使用 U1ATX/U1ARX 的 I/O 位置,
以便利 DEBUG 的工作能順利運作.

發表於: 2008/10/15 9:15
頂部


Re: 求助,关于初始化总是复位的错误,附原程序,谢谢
#8
中級會員
中級會員


你好!

沒有在你貼上的程序中看到 U2TX 與 U2RX 中斷程序,
所以很可能是你在 UART2_init() 中致能中斷所造成的,
(可能 U2TX = 1 後即進入 U2TX 中斷了...)

請修改

IFS1bits.U2TXIF = 0; // Clear the Transmit Interrupt Flag
IEC1bits.U2TXIE = 1; // Enable Transmit Interrupts
IFS1bits.U2RXIF = 0; // Clear the Recieve Interrupt Flag
IEC1bits.U2RXIE = 1; // Enable Recieve Interrupts



IFS1bits.U2TXIF = 0; // Clear the Transmit Interrupt Flag
IEC1bits.U2TXIE = 0; // Disable Transmit Interrupts
IFS1bits.U2RXIF = 0; // Clear the Recieve Interrupt Flag
IEC1bits.U2RXIE = 0; // Disable Recieve Interrupts

然後看你需要做中斷處理時再設定 U2TXIE 與 U2RXIE

Good Luck !!!!!

發表於: 2008/10/13 13:47
頂部


Re: C18 // 註解用於 socket 上的問題
#9
中級會員
中級會員


你好!
如果是希望字串內容為 at^siss=1,address,"socktcp://123.205.192.117:3000" 這樣的話.

請試試敘述成

const rom far unsigned char RomMsg15[] = "at^siss=1,address,\"socktcp://123.205.192.117:3000\"";

反斜線同樣可將下一個相連的雙引號當作為字串的內容喔!

發表於: 2008/9/6 9:34
頂部


Re: 請問幾個關於 PIC24FJ256GA108 的問題
#10
中級會員
中級會員


當要使用更大量的 const 資料時, 宣告 const 資料時請指定放入 program 的區域中,
如下所示, 可以不受 PSV 範圍的限制.
*** 但是讀取資料亦不受 PSV 讀取協助, 請使用 tblrdl 方式來讀取
*** 又或者你的 RAM 有足夠空間時,
*** 先行以 _memcpy_p2d16(void *dest, _prog_addressT src, unsigned int len) 複製到 RAM

宣告 const 放入 program 區域中

const unsigned int __attribute__((space(prog))) const_1[1000] = {1,2,3,4,5};
const unsigned int __attribute__((space(prog))) const_2[1000] = {1,2,3,4,5};
const unsigned int __attribute__((space(prog))) const_3[1000] = {1,2,3,4,5};
const unsigned int __attribute__((space(prog))) const_4[1000] = {1,2,3,4,5};
const unsigned int __attribute__((space(prog))) const_5[1000] = {1,2,3,4,5};

----------------------------------------------------------------------------------
使用 _memcpy_p2d16(void *dest, _prog_addressT src, unsigned int len) 複製到 RAM

#include "p24fj128ga108.h"
#include "libpic30.h"

const unsigned int __attribute__((space(prog))) const_1[1000] = {1,2,3,4,5};
const unsigned int __attribute__((space(prog))) const_2[1000] = {1,2,3,4,5};
const unsigned int __attribute__((space(prog))) const_3[1000] = {1,2,3,4,5};
const unsigned int __attribute__((space(prog))) const_4[1000] = {1,2,3,4,5};
const unsigned int __attribute__((space(prog))) const_5[1000] = {1,2,3,4,5};

_prog_addressT const_ptr;
unsigned int __attribute__((__far__)) const_temp[4096];

int main(void)
{
_init_prog_address(const_ptr, const_1); // 取得 const_1 的存放位址於 const_ptr
_memcpy_p2d16(const_temp, const_ptr, sizeof(const_1)); // 將 const_1 的內容複製到 RAM 中

return 0;
}

-----------------------------------------------------------------------------------
使用 tblrdl 的方式來讀取 const 資料內容

#include "p24fj128ga108.h"
#include "libpic30.h"

#define mem_const_int(const_value,const_p) \
{ TBLPAG = const_p >> 16; \
WREG1 = const_p & 0xFFFF; \
asm("TBLRDL.W [W1],W2"); \
const_value = WREG2; \
const_p += 2; }

#define mem_const_char(const_value,const_p) \
{ TBLPAG = const_p >> 16; \
WREG1 = const_p & 0xFFFF; \
asm("TBLRDL.B [W1],W2"); \
const_value = WREG2 & 0xFF; \
const_p ++; }

const unsigned int __attribute__((space(prog))) const_1[1000] = {1,2,3,4,5};
const unsigned int __attribute__((space(prog))) const_2[1000] = {1,2,3,4,5};
const unsigned int __attribute__((space(prog))) const_3[1000] = {1,2,3,4,5};
const unsigned int __attribute__((space(prog))) const_4[1000] = {1,2,3,4,5};
const unsigned int __attribute__((space(prog))) const_5[1000] = {1,2,3,4,5};

_prog_addressT const_index;
unsigned int const_get;

int main(void)
{
// 先取得 const_1 的位址放在 const_index 中, 以便接著順序取得 const 資料
_init_prog_address(const_index, const_1);
// 呼叫 mem_const_int(const_get, const_index), 會依序取得 const_1 的資料內容 [0], [1], [2]....
mem_const_int(const_get, const_index);
mem_const_int(const_get, const_index);
mem_const_int(const_get, const_index);
mem_const_int(const_get, const_index);

return 0;
}

發表於: 2008/7/26 15:49
頂部



(1) 2 3 4 ... 7 »



:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------