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

論壇索引


Board index » All Posts (powmien)




Re: AN1003 SD ctrl problem
#21
高級會員
高級會員


好像是 msb lsb 擺錯的關系.. struct 裡面的 C_SIZE 改成下面似乎就正確了...,但是C_SIZE_MULT 部份的話..spec 裡面提到SECTOR_SIZE 為7 bits ,不過struct 裡面把 SECTOR_SIZE 設為 5 bits ...

unsigned C_SIZE_U           :2;    //1    6
        
unsigned RESERVED_2         :2;
        
unsigned DSR_IMP            :1;
        
unsigned READ_BLK_MISALIGN  :1;
        
unsigned WRITE_BLK_MISALIGN :1;
        
unsigned READ_BL_PARTIAL    :1;

        
unsigned C_SIZE_H           :8;    //1    7

         
unsigned VDD_R_CURR_MAX     :3;    //1    8        
        
unsigned VDD_R_CURR_MIN     :3;
        
unsigned C_SIZE_L           :2;

發表於: 2006/11/20 14:50
頂部


AN1003 SD ctrl problem
#22
高級會員
高級會員


最近在玩SD card , 算是有點小進展, C18是用 V3_06, MPLAB 是 7.31 ,在讀取CSD 計算 SD card memory capacity資訊時卻一直算錯,下面的struct 是直接從AN1003 typedef.h 拿出來用的無修改, 但是C_SIZE_U, C_SIZE_H, C_SIZE_L 跟 C_SIZE_MULT_H , C_SIZE_MULT_L , 取出來的值似乎不正確, 我用256MB 的MMC 卡
直在接 MPLAB 的 WATCH 觀查 struct value得到:
C_SIZE_U=0X02
C_SIZE_H=0XCC
C_SIZE_L=0X02
組合起來為 0X0B32
((C_SIZE_U&0X03)<<10)|((C_SIZE_H)<<2)|(C_SIZE_L&0X03)
C_SIZE_MULT_H=0X03
C_SIZE_MULT_L=0X01
組合起來為0X07
((C_SIZE_MULT_H&0X03)<<1)|(C_SIZE_MULT_L&0X01)
由於C_SIZE/C_SIZE_MULT的值一直不正確後來直接看SD spec 用同一個struct 但是直接把對應的 byte 抓出來得到的值為
CSD CSDStatus;
CSDStatus=ReadCSD();
................................................
C_SIZE_U=CSDStatus._byte[6]&0X03; =>0X03
C_SIZE_H=CSDStatus._byte[7]; => 0XCC
C_SIZE_L=CSDStatus._byte[8]&0X03; =>0X03
組合起來為 0X0F32
C_SIZE_MULT_H=CSDStatus._byte[9]&0X03; =>0X02
C_SIZE_MULT_L=CSDStatus._byte[10]&0X01; =>0X01
組合起來為 0X05

這時後跟 READ_BL_LENTH 來計算就對了...
問題來了.. 那為何 struct 裡面宣告的 C_SIZE/C_SIZE_MULT 明明對應到正確的地方,但是讀回來卻是錯的....

實驗了一整個上午終於找到這樣的關聯性,所以想請教版主一下,究竟是我的問題還是?... 感謝....


typedef union
{
    
struct
    
{
        
DWORD _u320;
        
DWORD _u321;
        
DWORD _u322;
        
DWORD _u323;
    };
    
struct
    
{
        
byte _byte[16];
    };
    
struct
    
{
        
unsigned CSD_STRUCTURE      :2;
        
unsigned SPEC_VERS          :4;
        
unsigned RESERVED_3         :2;    //1    0
        
        
unsigned TAAC               :8;    //1    1
        
        
unsigned NSAC               :8;    //1    2
        
        
unsigned TRAN_SPEED         :8;    //1    3
        
        
unsigned CCC_H              :8;    //1    4
        
        
unsigned READ_BL_LEN        :4;
        
unsigned CCC_L              :4;    //1    5
        
        
        
unsigned READ_BL_PARTIAL    :1;
        
unsigned WRITE_BLK_MISALIGN :1;
        
unsigned READ_BLK_MISALIGN  :1;
        
unsigned DSR_IMP            :1;
        
unsigned RESERVED_2         :2;
        
unsigned C_SIZE_U           :2;    //1    6
        
        
unsigned C_SIZE_H           :8;    //1    7
        
        
unsigned C_SIZE_L           :2;    
        
unsigned VDD_R_CURR_MIN     :3;
        
unsigned VDD_R_CURR_MAX     :3;    //1    8
        
        
unsigned VDD_W_CUR_MIN      :3;
        
unsigned VDD_W_CURR_MAX     :3;
        
unsigned C_SIZE_MULT_H      :2;    //1    9
                
        
unsigned C_SIZE_MULT_L      :1;
        
unsigned SECTOR_SIZE        :5;
        
unsigned ERASE_GRP_SIZE_H   :2;    //1    10
        
        
unsigned ERASE_GRP_SIZE_L   :3;
        
unsigned WP_GRP_SIZE        :5;

        
unsigned WP_GRP_ENABLE      :1//bit 016 - 031
        
unsigned DEFAULT_ECC        :2;
        
unsigned R2W_FACTOR         :3;
        
unsigned WRITE_BL_LEN_H     :2;
        
        
unsigned WRITE_BL_LEN_L     :2;
        
unsigned WRITE_BL_PARTIAL   :1;
        
unsigned RESERVED_1         :5;
        
        
unsigned FILE_FORMAT_GRP    :1//bit 008 - 015
        
unsigned COPY               :1;
        
unsigned PERM_WRITE_PROTECT :1;
        
unsigned TMP_WRITE_PROTECT  :1;
        
unsigned FILE_FORMAT        :2;
        
unsigned ECC                :2;
        
        
unsigned CRC                :7//bit 000 - 007
        
unsigned NOT_USED           :1;
    };
CSD;

發表於: 2006/11/20 14:09
頂部


請問一下18f8520 SPI SCK CLOCK
#23
高級會員
高級會員


目前我用 18f8520 crystal 用10mhz
config bit 設成hs+pll ,所以為40mhz
請問一下 fosc 是用 10mhz 還是 40mhz 呢?
我spi 設成 fosc/64 量出來為153.6khz
計算起來應該是 10 mhz 這樣對嗎?

會發問的原因是我記得我昨天量是 625khz的(40mhz/64)
,今天卻是153.6khz,不知道是不是昨天精神晃忽看錯了,
config bits 我是寫在code 裡面,應該是不會跑掉才是,上來
請教確認一下.謝謝


發表於: 2006/11/17 12:11
頂部


Re: 請問PIC18F6520的接收電壓
#24
高級會員
高級會員


我用蠻多 iic 的device 都是 3.3v 的,
基本上沒什麼問題,倒是我用的pic 大部份都只能吃5v,做master的話有些slave device 會強調Vih 不能高於Vdd這時後控制iic時就要分壓。

如果做iic slave 的話 st buffer要0.8 VDD 才視為high ..
PIC 5V VDD 的話大約要4V , 才能視為high,不過之前實驗的結果3.3V 似乎就能視為high了,不過現在都會用244之類的ic提升到5V確保穩定度。

發表於: 2006/11/15 17:37
頂部


Re: C18 SPI 介面使用設定的問題
#25
高級會員
高級會員


找到問題了,因為我用MPLAB SIM 去模擬,所以不會真正發送資料,使得BF一直為0。
最近剛好發現 MPLAB SIM simulation 有軟体 LA 可以用就很高興的拿來用,i/o的做動還蠻正常的,用到SPI一直看不到資料發送誤以為設定一直是不正確的,一開始直接用ICD2跑就不會有這種問題了(○_o汗)....

發表於: 2006/11/15 15:31
頂部


C18 SPI 介面使用設定的問題
#26
高級會員
高級會員


參考了一些source code ,好像也沒特別的設定,不過我用Mplab sim 發現sck sdo 都沒反應,WriteSpi會一直停在等SSPSTATbits.BF flag ,請問是那邊有設定問題呢?


void main(void){
   
init_io();
   
init_timer();
   
OpenSPI(SPI_FOSC_64MODE_11SMPMID);
   
Nop();
   while(
1){
       
WriteSPI(0xaa);
   }
}

void init_io(void){

    
PORTA=0x3f;
    
LATA=0x3f;
    
TRISA=0x00;

    
PORTB=0x00;
    
LATB=0x00;
    
TRISB=0xff;

    
PORTC=0x00;
    
LATC=0x00;
    
TRISC=0x10;

    
PORTD=0x00;
    
LATD=0x00;
    
TRISD=0x00;

    
PORTE=0x00;
    
LATE=0x00;
    
TRISE=0x00;

    
PORTF=0x00;
    
LATF=0x02;
    
TRISF=0xcd;

    
PORTG=0X00;
    
LATG=0x18;
    
TRISG=0X00;

    
PORTH=0X00;
    
LATH=0x0C;
    
TRISH=0X03;

    
PORTJ=0x00;
    
LATJ=0x00;
    
TRISJ=0x01;

}

void init_timer(void)
{
    
_asm
        MOVLW 0x1f    
//B'00011111'        //DISABLE PRIORITY LEVEL
        
MOVWF RCON,0
        
//bit 7 IPEN:0 = Disable priority levels on interrupts (PIC16CXXX Compatibility mode)
        //bit 4 RI:1 = The RESET instruction was not executed
        //bit 3 TO:1 = After power-up, CLRWDT instruction or SLEEP instruction
        //bit 2 PD:1 = After power-up or by the CLRWDT instruction
        //bit 1 POR:1 = A Power-on Reset has not occurred   POR:0 A Power-on Reset occurred
        //bit 0 BOR:1 = A Brown-out Reset has not occurred  BOR:0 A Brown-out Reset occurred

        
MOVLW 0x80    //B'10000000'        //DISABLE EXTERNAL BUS
        
MOVWF MEMCON,0
        
//bit 7 EBDIS:1 = External system bus disabled, all external bus drivers are mapped as I/O ports

        
MOVLW 0xe0    //B'11100000'        //ENABLE UNMASKED PERIPHERAL INTERRUPT
        
MOVWF INTCON,0        //DEFAULT DISABLE ALL INTERRUPT

        
MOVLW 0xc0    //B'11000011'
        
MOVWF T0CON,0

        MOVLW 0x0f    
//B'00001111'        //A/D PORT CONFIG DIGITAL I/O
        
MOVWF ADCON1,0

        MOVLW 0x07    
//B'00000111'        //COMPARATOR OFF
        
MOVWF CMCON,0
    _endasm

}

發表於: 2006/11/13 13:43
頂部


Re: 請教C18的寫法
#27
高級會員
高級會員


找到解決的方法了,謝謝指點。
typedef union{
unsigned char Byte;
   
struct{
      
unsigned b0:1;
      
unsigned b1:1;
      
unsigned b2:1;
      
unsigned b3:1;
      
unsigned b4:1;
      
unsigned b5:1;
      
unsigned b6:1;
      
unsigned b7:1;
   }
bits;
}
_out;


_out out;
#define out_byte out.Byte
//---------------------------------------------------
#define out_bits out.bits
//---------------------------------------------------

BYTE SPI(BYTE outdata){
    
out_byte=outdata;
}


發表於: 2006/11/13 12:02
頂部


Re: 請教C18的寫法
#28
高級會員
高級會員


typedef    unsigned char    BYTE;
...................................
BYTE _out;
union {
  
struct {
    
unsigned b0:1;
    
unsigned b1:1;
    
unsigned b2:1;
    
unsigned b3:1;
    
unsigned b4:1;
    
unsigned b5:1;
    
unsigned b6:1;
    
unsigned b7:1;
  };
out=0;
..............................................
BYTE SPI(BYTE);
..............................................
BYTE SPI(BYTE outdata){
//    out=outdata;   <== compiler說型態錯誤,那要如何把outdata的資料放入out 比較方便?
    
}

發表於: 2006/11/13 11:53
頂部


請教C18的寫法
#29
高級會員
高級會員


這是截取CC5X 部份的程式碼,宣告pin腳的部份還ok, 不知道c18能不能寫到那麼簡明?

#pragma bit CS @ PORTC.2    // output for chip select CS
#pragma bit SCK @ PORTC.3    // clock output
#pragma bit SDO @ PORTC.5    // data output (PIC)
#pragma bit SDI @ PORTC.4    // data input (PIC)

char SPI(char out)  // software SPI function at about 620 kHz for a 20MHZ crystal
{
    
char in,i;
    for (
08i++)
    {
        
nop2();
        
SCK 0;          // falling edge of clock
        
nop();
        
SDO out.7;      // prepare data
        
nop();
        
out out<<1;     // shift output byte for next loop
        
nop2();
        
in in<<1;       // shift input data for next loop
        
SCK 1;          // rising edge of clock
        
nop();
        
in.0 SDI;       // read input data
    
}
    return 
in;
}



發表於: 2006/11/13 10:19
頂部


請教spi 的clock modes
#30
高級會員
高級會員


看datasheet 上面有寫 master mode時 clock modes 有四種,現在找到的 sd card 的spec 都沒看到時序圖之類的資訊,是不是這四種都是允許的呢?

不知道那裡有 sd card spi mode 的read/wrtie 時序圖?
謝謝。

發表於: 2006/11/6 12:13
頂部



« 1 2 (3) 4 5 6 ... 8 »



:::

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... ]

教育訓練中心

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