اطلاعیه

Collapse
No announcement yet.

فرستادن یه کد مثل 03H به یه ای سی یا ...

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    #16
    پاسخ : فرستادن یه کد مثل 03H به یه ای سی یا ...

    باز هم فرار کردید :mrgreen:
    این جدول زمان بندی چه طوریه ؟

    دیدگاه


      #17
      پاسخ : فرستادن یه کد مثل 03H به یه ای سی یا ...

      سلام
      با SPI کار کنم بهتره
      جواب سوال هام رو که نمیدید
      پس این یه صحفه متن رو ترجمه کنید
      6.3. SPI serial interface
      SPI synchronous serial interface signal lines include: SPI chip select input pin SCS, serial clock input
      pins SCK, serial data input pin SDI, serial data output pin SDO and interface busy status output pin BZ.
      Through SPI serial interface, CH376 can use less connection to connect to a variety of MCU, DSP, SPI
      serial bus of MCU, or a more long-range point to point connection.
      SCS pin of CH376 is driven by SPI chip select output pin or common output pins of MCU, SCK pin is
      driven by SPI clock output pin SCK of MCU, SDI pin driven by SPI data output pin SDO or MISO of MCU,
      SDO pin is connect to the SPI data input pin SDI or MISO of MCU. For SPI hardware interface,
      recommended SPI setting is CPOL = CPHA = 0 or CPOL = CPHA = 1, and the data bit sequence is high in
      the front MSB first. SPI interface of CH376 also supports MCU common I/O pin simulate SPI interface to
      communication.
      If INT # pin do not connect, you can get interrupt by query SDO pin, the method is let SDO pin
      exclusive one of MCU input pins, and through CMD_SET_SDO_INT command sets SDO pin do interrupt
      request output when the SCS chip select valid.
      SPI interface of CH376 supports SPI Mode 0 and SPI Mode 3, CH376 always input data from the SPI
      clock SCK rising edge, and output data when allows output from the SCK falling edge, data bit order is high
      in the former, counted 8 bits as a byte.
      The operation steps of SPI are:
      ① MCU generate SPI chip select to CH376, active with low-level;
      ② MCU sends a byte data according to SPI output mode, CH376 always received the first byte after
      SPI chip select SCS effective as a command code, the follow bytes as data;
      ③ SCM inquiry BZ pin waiting for SPI interface of CH376 is free, or directly delay TSC time (about
      1.5uS);
      ④ If the write operation, MCU send to CH376 a byte data to be written, waiting for SPI interface is
      free, MCU continues to send a number of bytes data to be written, CH376 receive in turn, until MCU forbid
      SPI Chip Select;
      ⑤ If the read operation, MCU receive a byte of data from CH376, waiting for SPI interface is free,
      MCU continues to receive a number of bytes data from CH376, until MCU forbid SPI Chip Select;
      ⑥ MCU forbid SPI Chip Select, to end the current SPI operation.
      The following figure is the SPI interface logic timing diagram, the former one is to send command 12H
      and write data 34H, the latter one is to send command 28H and read data 78H.
      برای صحفه 21 دیتاشیت هست
      اگه این صحفه رو ترجمه کنید فکر کنم دیگه کارم راه بیفته
      منظورم این نیست که هلو برو تو گلو :mrgreen:
      با تشکر فراوان


      دیدگاه


        #18
        پاسخ : فرستادن یه کد مثل 03H به یه ای سی یا ...

        اولش که قصه میگه

        بعدش


        For SPI hardware interface,
        recommended SPI setting is CPOL = CPHA = 0 or CPOL = CPHA = 1, and the data bit sequence is high in
        the front MSB first. SPI interface of CH376 also supports MCU common I/O pin simulate SPI interface to
        communication.


        یعنی شما باید spi رو تو مد CPOL = CPHA = 0 or CPOL = CPHA = 1 قرار بدید.
        بعدش


        The operation steps of SPI are:
        ① MCU generate SPI chip select to CH376, active with low-level;
        ② MCU sends a byte data according to SPI output mode, CH376 always received the first byte after
        SPI chip select SCS effective as a command code, the follow bytes as data;
        ③ SCM inquiry BZ pin waiting for SPI interface of CH376 is free, or directly delay TSC time (about
        1.5uS);
        ④ If the write operation, MCU send to CH376 a byte data to be written, waiting for SPI interface is
        free, MCU continues to send a number of bytes data to be written, CH376 receive in turn, until MCU forbid
        SPI Chip Select;
        ⑤ If the read operation, MCU receive a byte of data from CH376, waiting for SPI interface is free,
        MCU continues to receive a number of bytes data from CH376, until MCU forbid SPI Chip Select;
        ⑥ MCU forbid SPI Chip Select, to end the current SPI operation.


        یعنی برای کار شش مرحله داری یا شش نکته بگم بهتره.
        1. قبل از هر کاری mcu که میکرو باشه باید پایه cs رو صفر کنه تا فعال بشه.
        2. بعد از اون اولین بایتی که میفرسته به منزله دستور مورد نظر تلق میشه که باید به جدول دستورات مراجعه کنی.
        3. بعد حدود 1.5 میکرو ثانیه طول میکشه تا دستور پردازش بشه و باید delay بدی.
        4. اگه دستورت خوندنیه ، یعنی تو این دستور باید یه چیزی رو الان از آی سی بگیری خوب باید با توجه به دستورت که چی باشی صبر کنی آی سی کارش تموم شه و بعد دوباره ازش بخونی هر چند تا که لازمه و بعدش cs رو یک کنی.
        5. اگه دستورت نوشتنیه باز هم باید بنویسی و در نهایت cs رو یک کنی که به آی سی حالی کنی تموم شد.
        6. اگه دستورت هیچ کدوم از دو حالت بالا نباشه، یعنی نه منتظری که چیزی بگیری از آی سی و نه میخوای بفرستی خوب باز هم باید cs رو 1 کنی که آی سی کار اجرای دستور رو شروع کنه.

        من هم برنامه ای که نوشتم و ظرفیت فلش و مقدار خالیش رو میده میزارم شاید به درد کسی خورد. شما که بسکام کار میکنی


        کد:
        /*
         * definitions.h
         *
         * Created: 11/5/2011 9:49:18 PM
         * Author: Mostafa
         */ 
        
        
        #ifndef DEFINITIONS_H_
        #define DEFINITIONS_H_
        
        #define MSD_CMD_GET_IC_VER				0x01		//Obtain chip and firmware version number
        #define MSD_CMD_SET_BAUDRATE			0x02		//Set serial communication baud rate
        #define MSD_CMD_ENTER_SLEEP				0x03		//Go to low-power and suspending
        #define MSD_CMD_RESET_ALL				0x05		//Execute hardware reset
        #define MSD_CMD_CHECK_EXIST				0x06		//Test communication interface and working status
        #define MSD_CMD_SET_SD0_INT				0x0B		//Set interrupt Mode of SD0 in SPI 
        #define MSD_CMD_GET_FILE_SIZE			0x0C		//Get the current file length
        #define MSD_CMD_SET_USB_MODE			0x15		//Configure the work mode of USB 
        #define MSD_CMD_GET_STATUS				0x22		//Get interruption status and cancel requirement
        #define MSD_CMD_RD_USB_DATA0			0x27		//Read data from current interrupt port buffer of USB or receive buffer of host port
        #define MSD_CMD_WR_USB_DATA				0x2C		//Write data to transfer buffer of USB host 
        #define MSD_CMD_WR_REQ_DATA				0x2D		//Write requested data block to internal appointed buffer
        #define MSD_CMD_WR_OFS_DATA				0x2E		//Write data block to internal buffer with appointed excursion address
        #define MSD_CMD_SET_FILE_NAME			0x2F		//Set the file name which will be operated 
        #define MSD_CMD_DISK_CONNECT			0x30		//Check the disk connection status 
        #define MSD_CMD_DISK_MOUNT				0x31		//Initialize disk and test disk ready
        #define MSD_CMD_FILE_OPEN				0x32		//Open file or catalog, enumerate file and catalog
        #define MSD_CMD_FILE_ENUM_GO			0x33		//Go on to enumerate file and catalog
        #define MSD_CMD_FILE_CREATE				0x34		//Create file
        #define MSD_CMD_FILE_ERASE				0x35		//Delete file
        #define MSD_CMD_FILE_CLOSE				0x36		//Close the open file or catalog
        #define MSD_CMD_DIR_INF0_READ			0x37		//Read the catalog information of file
        #define MSD_CMD_DIR_INF0_SAVE			0x38		//Save catalog information of file
        #define MSD_CMD_BYTE_LOCATE				0x39		//Move the file pointer take byte as unit
        #define MSD_CMD_BYTE_READ				0x3A		//Read data block from current location take byte as unit
        #define MSD_CMD_BYTE_RD_GO				0x3B		//Continue byte read
        #define MSD_CMD_BYTE_WRITE				0x3C		//Write data block from current location take unit as unit
        #define MSD_CMD_BYTE_WR_GO				0x3D		//Continue byte write
        #define MSD_CMD_DISK_CAPACITY			0x3E		//Check disk physical capacity
        #define MSD_CMD_DISK_QUERY				0x3F		//Check disk space
        #define MSD_CMD_DIR_CREATE				0x40		//Create catalog and open or open the existed catalog
        #define MSD_CMD_SEG_LOCATE				0x4A		//Move file pointer from current location take fan as unit
        #define MSD_CMD_SEC_READ				0x4B		//Read data block from current location take fan as unit
        #define MSD_CMD_SEC_WRITE				0x4C		//Write data block from current location take fan as unit
        #define MSD_CMD_DISK_BOC_CMD			0x50		//Execute B0 transfer protocol command to USB Storage
        #define MSD_CMD_DISK_READ				0x54		//Read physical fan from USB storage device
        #define MSD_CMD_DISK_RD_GO				0x55		//Go on reading operation of USB storage device
        #define MSD_CMD_DISK_WRITE				0x56		//Write physical fan to USB storage device
        #define MSD_CMD_DISK_WR_GO				0x57		//Go on writing operation of USB storage device
        
        // ---------------------------------------------------------------------------------------------------
        #define MSD_RET_SUCCESS					0x51		//Operation successful
        #define	MSD_RET_ABORT					0x5F		//Operation failure
        
        #define MSD_USB_INT_SUCCESS				0x14		//Success of SD card or USB transaction or transfer operation 
        #define MSD_USB_INT_CONNECT				0x15		//Detection of USB device attachment 
        #define MSD_USB_INT_DISCONNECT			0x16		//Detection of USB device detachment 
        #define MSD_USB_INT_BUF_OVER			0x17		//Data error or Buffer overflow
        #define MSD_USB_INT_USB_READY			0x18		//USB device has initialized (appointed USB address) 
        #define MSD_USB_INT_DISK_READ			0x1D		//Read operation of storage device
        #define MSD_USB_INT_DISK_WRITE			0x1E		//Write operation of storage device 
        #define MSD_USB_INT_DISK_ERR			0x1F		//Failure of USB storage device
        
        #define MSD_ERR_OPEN_DIR				0x41		//Open directory address is appointed
        #define MSD_ERR_MISS_FILE				0x42		//File doesn’t be found which address is appointed, maybe the name is error
        #define MSD_ERR_FOUND_NAME				0x43		//Search suited file name, or open directory according the request, open file in actual
        #define MSD_ERR_DISK_DISCON				0x82		//Disk doesn’t connect, maybe the disk has cut down
        #define MSD_ERR_LARGE_SECTOR			0x84		//Fan is too big, only support 512 bytes
        #define MSD_ERR_TYPE_ERROR				0x92		//Disk partition doesn’t support, re-prartition by tool
        #define MSD_ERR_BPB_ERROR				0xA1		//Disk doesn’t format, or parameter is errot, re-formate by WINDOWS with default parameter
        #define MSD_ERR_DISK_FULL				0xB1		//File in disk is full, spare space is too small
        #define MSD_ERR_FDT_OVER				0xB2		//Many file in directory, no spare directory, clean up the disk, less than 512 in FAT12/FAT16 root directory
        #define MSD_ERR_FILE_CLOSE				0xB4		//File is closed, re-open file if need
        
        #endif /* DEFINITIONS_H_ */



        کد:
        /*
         * MSDlib.h
         *
         * Created: 11/5/2011 10:19:59 PM
         * Author: Mostafa
         */ 
        
        
        #ifndef MSDLIB_H_
        #define MSDLIB_H_
        
        #include "definitions.h"
        
        void msd_init();
        void msd_command(char cmd);
        
        char msd_isconnect();
        char msd_mount();
        void msd_dismount();
        char msd_updateDiskCapacity();
        
        volatile char msd_timeout;
        
        struct diskSpaces
        {
        	unsigned long msd_diskSize;	// in 512 sectors
        	unsigned long msd_diskFree;	// in 512 sectors
        }diskSpaces;
        
        #endif /* MSDLIB_H_ */



        کد:
        /*
         * MSDlib.c
         *
         * Created: 11/14/2011 1:05:36 PM
         * Author: Mostafa
         */
        
        #include "MSDlib.h"
        #include "MSDmacro.h"
        #include "msd_uart.h"
        
        void msd_init()
        {
        	MSD_UART_INIT();
        }
        
        void msd_flushBuffer()
        {
        	while(MSD_UART_RECIVED())
        		MSD_UARTGET();
        }
        
        void msd_command(char cmd)
        {
        	msd_flushBuffer();
        	MSD_UARTPUT(0x57);
        	MSD_UARTPUT(0xAB);
        	MSD_UARTPUT(cmd);
        }
        
        //1000ms resolation
        char msd_waitonebyte(char t)
        {
        	unsigned int i;
        	msd_timeout = 0;
        	t = 26 - t;
        	for(i = 0; i < 50000; i+=t)
        	{
        		if(MSD_UART_RECIVED())
        			return MSD_UARTGET();
        		MSD_Delay_us(50);
        	}
        	
        	msd_timeout = 1;
        	return 0xff;
        }
        
        char msd_getversion()
        {
        	char t;
        	msd_command(MSD_CMD_GET_IC_VER);
        	t = msd_waitonebyte(3);
        	if( t == 0xff )
        		return MSD_RET_ABORT;
        	return t;
        }
        
        char mds_setmode(char mode)
        {
        	char ret;
        	
        	msd_command(MSD_CMD_SET_USB_MODE);
        	MSD_UARTPUT(mode);
        	ret = msd_waitonebyte(5);
        	msd_waitonebyte(1);
        	return ret;
        }
        
        char msd_isconnect()
        {
        	msd_command(MSD_CMD_DISK_CONNECT);
        	return msd_waitonebyte(3);
        }
        
        char msd_mount()
        {
        	char ret , trys;
        	
        	for(trys = 0; trys < 3 ; trys++)
        	{
        		// check version
        		ret = msd_getversion();
        		if(ret == MSD_RET_ABORT)
        			continue;
        		
        		// set mode of operation
        		ret = mds_setmode(6);
        		if(ret != MSD_RET_SUCCESS)
        			continue;
        		
        		// mount mass storage
        		msd_command(MSD_CMD_DISK_MOUNT);
        		ret = msd_waitonebyte(20);
        		if(ret == MSD_USB_INT_SUCCESS)
        			return MSD_USB_INT_SUCCESS;
        	}
        	
        	return ret;
        }
        
        char msd_updateDiskCapacity()
        {
        	char ret , trys;
        	unsigned char i;
        	char *temp = &diskSpaces;
        	
        	for(trys = 0; trys < 3 ; trys++)
        	{
        		// mount mass storage
        		msd_command(MSD_CMD_DISK_QUERY);
        		ret = msd_waitonebyte(20);
        		if(ret != MSD_USB_INT_SUCCESS)
        			continue;
        		
        		//09 E8 3F 77 00 68 61 55 00 03 14
        		msd_command(MSD_CMD_RD_USB_DATA0);
        		ret = msd_waitonebyte(3);
        		if(ret != 0x09)
        			continue;
        		for(i = 0; i < 8; i++)
        		{
        			*temp = msd_waitonebyte(1);
        			temp++;
        			if(msd_timeout)
        				continue;
        		}
        				
        		diskSpaces.msd_diskSize /= 2;	// convert to kilobyte
        		diskSpaces.msd_diskFree /= 2;	// convert to kilobyte
        		
        		return MSD_USB_INT_SUCCESS;
        	}
        	
        	return MSD_RET_ABORT;
        }



        کد:
        /*
         * CH375_Test1.c
         *
         * Created: 11/5/2011 9:41:27 PM
         * Author: Mostafa
         */ 
        
        #include <avr/io.h>
        #include "MSD Lib/MSDlib.h"
        #include "lcd_lib.h"
        #include <stdio.h>
        #include <avr/interrupt.h>
        
        int main(void)
        {
        	LCDinit();
        	LCDGotoXY(0,0);
        	
        	sei();
        	
        	msd_init();
        	
        	if( msd_mount() == MSD_USB_INT_SUCCESS)
        	{
        		msd_updateDiskCapacity();
        		printf_P((char*)PSTR("T:%ld") ,diskSpaces.msd_diskSize);
        		LCDGotoXY(0,1);
        		printf_P((char*)PSTR("T:%ld") ,diskSpaces.msd_diskFree);
        	}
        	
          while(1)
          {
            //TODO:: Please write your application code 
          }
        }
        بت در بغل و به سجده پیشانی ما کافر زده خنده بر مسلمانی ما
        اسلام به ذات خود ندارد عیبی هر عیب که هست در این مسلمانی ماست

        دیدگاه


          #19
          پاسخ : فرستادن یه کد مثل 03H به یه ای سی یا ...

          با تشکر از پاسختون
          یعنی فقط باید سیم های MOSI MISO SCK CS رو وصل کنم با VCC و GND هم 6 تا سیم میشه ؟
          این CS که برای رم SD هست ؟
          SCS همون CS که شما گفتی هست ؟ اگه این همون باشه جواب سوال بالایی رو نمی خواد دیگه
          پروتکل SPI باود هم نداره با هر سرعتی میشه کار کرد ؟
          اون شکل پاین همن نوشته توی دیتاشت می خواست همینو بگه ؟ صحفه 21
          در مورد SMD به DIP هم شنبه میرم میدم بیرون درست کنه ؟ تونستم درست کنم اما موقع سوراخ کردن خراب شد :mrgreen:
          باز هم تشکر می کنم ممنون

          دیدگاه


            #20
            پاسخ : فرستادن یه کد مثل 03H به یه ای سی یا ...

            نوشته اصلی توسط erfan m
            با تشکر از پاسختون
            یعنی فقط باید سیم های MOSI MISO SCK CS رو وصل کنم با VCC و GND هم 6 تا سیم میشه ؟
            SCS همون CS که شما گفتی هست ؟
            پروتکل SPI باود هم نداره با هر سرعتی میشه کار کرد ؟
            اون شکل پاین همن نوشته توی دیتاشت می خواست همینو بگه ؟ صحفه 21
            خواهش میکنم
            فکر کنم. اصولا یه دستگاه تو مد spi باید فقط با همینها کار کنه.
            بله جفتش یکیه
            با هر سرعتی دوست داری
            خیلی چیزا میخواد بگه یکیش اینه
            بت در بغل و به سجده پیشانی ما کافر زده خنده بر مسلمانی ما
            اسلام به ذات خود ندارد عیبی هر عیب که هست در این مسلمانی ماست

            دیدگاه


              #21
              پاسخ : فرستادن یه کد مثل 03H به یه ای سی یا ...

              سلام دوستان
              رفتم SMD به DIP رو گفتم اودم لحیمش کردم این برنامه رو هم نوشتم اما کار نکرد :cry2: :cry2: :cry2:
              $regfile = "m32def.dat"
              $crystal = 16000000

              Config Spi = Hard
              Config Lcd = 16 * 2
              Config Lcdpin = Pin , Rs = Pina.5 , E = Pina.4 , Db4 = Pina.3 , Db5 = Pina.2 , Db6 = Pina.1 , Db7 = Pina.0
              Dim A As Byte
              Dim Send As Byte
              Spiinit
              Do
              Send = &H30
              Reset Portb.0
              Spiout Send , 1
              Set Portb.0
              Waitms 2
              Reset Portb.0
              Spiin A , 1
              Home L
              Lcd A
              If A = &H51 Then
              Cls
              Lcd "YES"
              End If
              If A = &H5F Then
              Cls
              Lcd "NO"
              End If
              Waitms 200
              Cls
              Loop
              End


              چه بلایی سرش بیارم که کار کنه ؟
              SPI یا باید بخونه یا باید بفرسه این درست هست دیگه ؟
              شرایط کار با UART رو هم می بگید ؟
              با تشکر

              دیدگاه


                #22
                پاسخ : فرستادن یه کد مثل 03H به یه ای سی یا ...

                SPI یا باید بفرسه یا بگیره هر دوش با هم نمی شه من داشتم با این SPI کار میکردم
                برای همین با UART کار کنم بهتره
                باود رو چه جوری تنظیم کنم :question:
                اگر این نهوه کار با UART هست اگر برام ترجمش کنید ممنون می شم
                6.4. Asynchronous serial port
                CH376 serial asynchronous serial data format is not compatible with CH375, and does not support
                external firmware USB device mode.
                Asynchronous serial signal line includes: serial data input pin RXD and serial data output pin TXD.
                Through the serial interface, CH376 and MCU, DSP can be a more long-distance connection with the
                least connection.
                RXD and TXD of CH376 can be connected to the MCU serial data output pin and serial data input pin
                respectively.
                CH376 serial data format is the standard byte transmission mode, include 1 start bit, 8 data bits, 1 stop
                bit.
                CH376 supports both hardware-set the default serial communication baud rate, also supports MCU
                select the appropriate communication baud rate at any time by CMD_SET_BAUDRATE command. Every
                time after power-on reset, CH376 default serial communication baud rate is set by BZ/D4, SCK/D5, SDI/D6
                three pin power level combination, refer to the following table (in the table 0 denote low-level , 1 denote
                high-level or un-connection).

                In order to distinguish between command code and data, CH376 asked MCU through the serial port to
                send two synchronization code bytes (57H and ABH), and then send command code, follow send data or
                receiving data. CH376 will check time interval between the two synchronization code, synchronization code
                and command code. If the time interval is greater than serial input timeout SER_CMD_TIMEOUT (about
                32mS), then CH376 will discard the synchronization code and command package. Serial command operation
                steps are as follows:
                ① MCU send CH376 the first synchronization code 57H through serial port;
                ② MCU send the second synchronous code 0ABH to CH376;
                ③ MCU send command code to CH376;
                ④ If this command have input data, then send CH376 input data in turn, one byte one time;
                ⑤ If this command have output data, then receive output data from CH376 in turn, e one byte one time;
                ⑥ Command complete, some commands generate interrupt message after execute complete and send
                interrupt state code through serial port, MCU can suspended or turn to step ① to continue executing the
                next command.


                اینم تر جمه کنید
                6. Functions Description
                6.1 MCU Communication Interface
                It supports three kinds of communication interface between CH376 and MCU: 8-bit parallel interface,
                SPI synchronous serial interface, UART interface. When chip power-on reset, CH376 will sample WR#,
                RD#, PCS#, A0, RXD, TXD pin state, according to the configuration state of these pins combination
                selection communication interface, consult to the following table (in the table X denote not care about this
                bit, 0 denote low-level, 1 denote high-level or un-connection).

                There are two communication interfaces between CH376T and MCU: SPI synchronous serial interface,
                UART interface. When chip power-on reset, CH376T will sample SPI state, when SPI# is low-level, select
                SPI interface, SPI# is high-level select UART interface.
                INT# pin of CH376 output interrupt request is active with low-level in default, it can be connected
                to the MCU interrupt input pin or common input pin, MCU can get interrupt request of CH376 by using
                interrupt mode or query mode. To save pins, MCU can not connect to INT# pin of CH376, but get interrupt
                by other ways.

                باتشکر فراوان

                دیدگاه


                  #23
                  پاسخ : فرستادن یه کد مثل 03H به یه ای سی یا ...

                  سلام
                  وقتی بخوام به این ای سی بفرسم باید از دستور printbin استفاده کنم یا دستور print وقتی خواستم بگیرم باید از دستور input یا inputhex یا اینتراپت
                  جواب بدید دا :job:

                  دیدگاه

                  لطفا صبر کنید...
                  X