'---------------------------------------------------------------------------------------- ' Name: CompactFlash_Demo_001.TIG ' Type: TIGER-BASIC(tm) Source Code ' Purpose: Sample of how to control the serial CF module by creating a file on CF card ' and writing some data to it through serial port 0 (with HW hardshake) ' ' (C) - Copyright Wilke Technology, P.O.Box 1727, D-52018 Aachen, Germany '---------------------------------------------------------------------------------------- ' ' Thank you for using BASIC Tigers in your products. If you have questions, ideas ' or special needs, please contact your next distributor or the Tiger support team ' and visit our web site: ' ' Wilke Technology GmbH ' The Tiger Support Team ' P.O.Box 1727, D-52018 Aachen, Germany ' Krefelder Str. 147, D-52070 Aachen, Germany ' ' email: support@wilke-technology.com (english) ' email: support@wilke.de (german) ' Phone: +49 (241) 918 900 Mo to Fr, 7:00 to 16:00 (GMT) ' Fax: +49 (241) 918 9068 ' ' New information, new drivers and free downloads see: ' ' www.wilke-technology.com (english) ' www.wilke.de (german) ' ' Sincerely, ' ' Your Tiger Support Team ' '---------------------------------------------------------------------------------------- ' ' This program demonstrates how to communicate with the CF module by creating a file on ' the CF card and writing data to it. For communication SER0 is used, so the following ' connections between CF module and BASIC-Tiger have to be made: ' ' ' Tiger CF Module ' !------------! !------------! ' ! ! ! ! ' ! L90 (TxD0) ! --------> ! OST4 (RxD) ! ' ! ! ! ! ' ! L91 (RxD0) ! <-------- ! OST5 (TxD) ! ' ! ! ! ! ' ! L92 (CTS0) ! <-------- ! OST8 (CTS) ! * pin of CF module is designated as CTS, but ' ! ! ! ! is in fact output ' ! L95 (RTS0) ! --------> ! OST9 (RTS) ! * pin of CF module is designated as RTS, but ' ! ! ! ! is in fact input ' !------------! !------------! ' ' ' By default the communication parameters are 9600 baud, 8 data bits, no parity, ' 1 stop bit. We use this default for the demo program, baudrates of up to 38400 baud ' are possible. Commands resulting in an error will terminate the program, detailed ' evaluation on reason of error is not done, although there is a command for that. ' '---------------------------------------------------------------------------------------- USER_VAR_STRICT ' variables must be declared #INCLUDE DEFINE_A.INC ' general definitions #INCLUDE UFUNC3.INC ' User-Function-Codes #DEFINE FILENAME "TESTFILE.TXT" ' name of file to be created #DEFINE RECORDS 100 ' number of records to be written #DEFINE TIMEOUT 5000 ' timeout for waiting for answer STRING ANS$ ' for received answers TASK MAIN ' begin task MAIN BYTE RecNr ' for write loop LONG T ' for timer ticks INSTALL_DEVICE #LCD, "LCD1.TDD" ' install LCD driver INSTALL_DEVICE #SER, "SER1B_K1.TDD",& ' install SERIAL + set the baudrates: BD_9_600, DP_8N, JA, BD_9_600, DP_8N, JA '<-----Ser-Ch-0-----> <-----Ser-Ch-1-----> ' for each channel: Baudrate, Data-/Parity, Receive-on-Error Flag PRINT #LCD, "<1>CompactFlash Demo" ' RUN_TASK READ_ANSWER ' start task for serial receive PUT #SER, #0, #UFCO_OBU_ERASE, 0 ' erase serial output buffer on ser0 '..................... '. Is Card Inserted? . '..................... ANS$ = "" ' clear answer string PRINT #SER,#0, "at+cardpresent" ' check if card is inserted T = TICKS() ' set start time WHILE LEN(ANS$)=0 AND DIFF_TICKS(T)A<0><1><240>"; ' cursor to line 1, column 0 IF LEN(ANS$)=0 THEN ' if no answer PRINT #LCD, "No communication" ' output to LCD GOTO Exit ' end program ENDIF ' IF ANS$="ERROR" THEN ' if answer indicates error PRINT #LCD, "No CF card inserted" ' output to LCD GOTO Exit ' end program ENDIF ' PRINT #LCD, "found CF card" ' output to LCD '................... '. Create new file . '................... ANS$ = "" ' clear answer string PRINT #SER,#0, "at+create "; FILENAME ' create new file on CF card T = TICKS() ' set start time WHILE LEN(ANS$)=0 AND DIFF_TICKS(T)A<0><2><240>"; ' cursor to line 2, column 0 IF LEN(ANS$)=0 THEN ' if no answer PRINT #LCD, "No communication" ' output to LCD GOTO Exit ' end program ENDIF ' IF ANS$="ERROR" THEN ' if answer indicates error PRINT #LCD, "Can't create file" ' output to LCD GOTO Exit ' end program ENDIF ' PRINT #LCD, FILENAME;" created" ' output to LCD '.............................. '. Prepare writing datastream . '.............................. ANS$ = "" ' clear answer string PRINT #SER,#0, "at+datastream" ' prepare data transmission as datastream T = TICKS() ' set start time WHILE LEN(ANS$)=0 AND DIFF_TICKS(T)A<0><3><240>"; ' cursor to line 3, column 0 IF LEN(ANS$)=0 THEN ' if no answer PRINT #LCD, "No communication" ' output to LCD GOTO Exit ' end program ENDIF ' IF ANS$="ERROR" THEN ' if answer indicates error PRINT #LCD, "Streaming mode fail" ' output to LCD GOTO Exit ' end program ENDIF ' PRINT #LCD, "Writing data..." ' output to LCD '...................... '. Write data to file . '...................... ANS$ = "" ' clear answer string PRINT #LCD, "<27>A<0><3><240>"; ' cursor to line 3, column 0 FOR RecNr = 1 TO RECORDS ' write defines no. of records PRINT #SER,#0, "Timer ="; TICKS() ' write timer ticks to file WAIT_DURATION 250 ' wait 250 ms IF ANS$="ERROR" THEN ' if answer indicates error (answer during ' stream might indicate 'disk full') PRINT #LCD, "Error writing file" ' output to LCD GOTO Exit ' end program ENDIF ' NEXT ' next record LOOP 3 ' 3 times PRINT #SER,#0, "+"; ' part of stop sequence WAIT_DURATION 600 ' must be minimum of 500ms ENDLOOP WHILE LEN(ANS$)=0 AND DIFF_TICKS(T) 0 THEN ' if characters in input buffer GET #SER, #0, 1, CH ' read on character IN$ = IN$ + CHR$(CH) ' append to temporary string IF CH = 10 THEN ' if ascii 10 (LF) ANS$ = LEFT$(IN$, LEN(IN$)-2) ' copy answer to answer string without CR/LF IN$ = "" ' clear temporary string again ENDIF ' ENDIF ' NEXT ' end of endless loop END ' end of task