Re: Counting led blinks..
Hi, I'm sorry about that(I'm misleading the thread), anyway I borrowed an sdcard from a friend...but he never tested it yet and doesn't have datasheet..hopefully I don't blow it up :)
Here are the List I done & planning to do on my project in this thread.
1. Use Timer/Counter from TIMER0 for multi coin-acceptor(pic16F877 and 18F4550) -Done
2. Test RTC and Sdcard separate program- Done
3. Incorporating Multi coin acceptor-RTC and Keypad on 4550 - Done (I need the keypad for access and view settings.)
4. Incorporate SDcard for saving RTC data and number of coins dropped - not yet
5. Use USB CDC to dump data(rtc and number of coins) from SDcard to terminal communicator - not yet
I appreciated the help and the knowledge I got on this forum...not easy task(for me) but you encourage me to try it out...:)
thanks again,
tacbanon
1 Attachment(s)
Re: Counting led blinks..
Hi, I have only one 4550 and I want to try it to another chip, I only have pic18f2550..I followed some instructions to comment the default config fuse in PBP INC files. I tried to compile this part of the code..
Code:
'<FL_PIC18F2550>' '<FL_PBPL>'
DEFINE OSC 48
@ __CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
@ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
@ __CONFIG _CONFIG2L, _PWRT_ON_2L & _VREGEN_ON_2L
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
@ __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
Include "modedefs.bas"
' Alias PIC pins and registers for SD/MMC card
SD_WE VAR PORTA.4 ' SD card write protect
SD_WE_TRIS VAR TRISA.4 ' SD card write protect direction
SDI VAR PORTA.5 ' SPI data in SD #7
SDI_TRIS VAR TRISA.5 ' SPI data in direction
SCL VAR PORTA.3 ' SPI clock SD #5
SCL_TRIS VAR TRISA.3 ' SPI clock direction
SD_CS VAR PORTC.2 ' SD card chip select SD #1
SD_CS_TRIS VAR TRISC.2 ' SD card chip select direction
SD_CD VAR PORTC.0 ' SD card detect
SD_CD_TRIS VAR TRISC.0 ' SD card detect direction
SDO VAR PORTC.1 ' SPI data out SD #2
SDO_TRIS VAR TRISC.1 ' SPI data out direction
But gives me the following compilation error...
Attachment 6109
regards,
tacbanon
Re: Counting led blinks..
Use the same configs for the 2550 as you did for the 4550.
The only thing you need to do to move to the 2550 is change some pin assignments if you were using some on the 4550 that the 2550 does not have.
Make sure you have all of the needed files in the new project directory.
Re: Counting led blinks..
Thanks mackrackit, I just found out that the sdcard module I ordered will take a while(2weeks from china). The sdcard I borrowed did not work either.In the meantime...I will be working on the keypad codes for accessibility feature of this project...be back soon.
Re: Counting led blinks..
Hi, I got my new sdcard just the other day...now I've been trying to make following code work... I did tried to connect to another ports/pins but was not able to make it run.
Code:
Include "modedefs.bas"
asm
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm
DEFINE OSC 48
' Alias PIC pins and registers for SD/MMC card
SD_WE VAR PORTA.4 ' SD card write protect
SD_WE_TRIS VAR TRISA.4 ' SD card write protect direction
SDI VAR PORTA.5 ' SPI data in SD #7
SDI_TRIS VAR TRISA.5 ' SPI data in direction
SCL VAR PORTA.3 ' SPI clock SD #5
SCL_TRIS VAR TRISA.3 ' SPI clock direction
SD_CS VAR PORTC.2 ' SD card chip select SD #1
SD_CS_TRIS VAR TRISC.2 ' SD card chip select direction
SD_CD VAR PORTC.0 ' SD card detect
SD_CD_TRIS VAR TRISC.0 ' SD card detect direction
SDO VAR PORTC.1 ' SPI data out SD #2
SDO_TRIS VAR TRISC.1 ' SPI data out direction
' Include the SD/MMC subroutines (found in http://melabs.com/resources/samples/pbp/sdfs3.zip)
cnt var word
cnt = 0
Include "SDFS.PBP"
SDC_UseHardSPI = TRUE ' Use hardware SSP port for SPI.
ADCON1 = 15 ' All I/O pins digital
Pause 100
' FSInit initializes the card and reads all the preliminary information from it
Gosub FSInit
Serout2 PORTC.6, 84, ["Init: ", Dec FAT_error, " ", Dec SDC_status, " ", Dec SDC_response, $d, $a]
If (FAT_error != 0) Then Stop
' This section defines a specific short (8.3) filename
' Note that spaces are use in empty elements and must be upper case for Windows
FAT_FileName[0] = "R"
FAT_FileName[1] = "E"
FAT_FileName[2] = "C"
FAT_FileName[3] = "O"
FAT_FileName[4] = "R"
FAT_FileName[5] = "D"
FAT_FileName[6] = "S"
FAT_FileName[7] = " "
FAT_FileName[8] = "T"
FAT_FileName[9] = "X"
FAT_FileName[10] = "T"
FAT_seconds = 5
FAT_minutes = 30
FAT_hours = 8
FAT_day = 1
FAT_month = 1
FAT_year = 28
' Open a file for write
FAT_mode = "A" ' Write mode
Gosub FSfopen ' Open file pointed to by Byte array FAT_FileName
Serout2 PORTC.6, 84, ["Open for write: ", Dec FAT_error, $d, $a]
If (FAT_error != 0) Then Stop
cnt = cnt + 5
' Write to file
FAT_src[0] = $30+cnt
FAT_src[1] = "M"
FAT_src[2] = "I"
FAT_src[3] = "C"
FAT_src[4] = "R"
FAT_src[5] = "O"
FAT_src[6] = "T"
FAT_src[7] = "E"
FAT_src[8] = "S"
FAT_src[9] = "T"
FAT_src[10] = 10
FAT_count = 11
Gosub FSfwrite
Serout2 PORTC.6, 84, [ "Write ", Dec FAT_error, $d, $a]
If (FAT_error != 0) Then Stop
' Close file
Gosub FSfclose
Serout2 PORTC.6, 84, [ "Close ", Dec FAT_error, $d, $a]
End
Haredware: Pic16F4550, PBP2.60, crystal 20Mhz
The alias PIC pins and registers for SDcard is a copy from Macrackit, Can you tell me what I'm doing wrong?
The alias pins below works with no problem..
Code:
' Alias PIC pins and registers for SD/MMC card
SD_WE Var PORTA.4 ' SD card write protect
SD_WE_TRIS Var TRISA.4 ' SD card write protect direction
SDI Var PORTB.0 ' SPI data in
SDI_TRIS Var TRISB.0 ' SPI data in direction
SCL Var PORTB.1 ' SPI clock
SCL_TRIS Var TRISB.1 ' SPI clock direction
SD_CS Var PORTB.3 ' SD card chip select
SD_CS_TRIS Var TRISB.3 ' SD card chip select direction
SD_CD Var PORTB.4 ' SD card detect
SD_CD_TRIS Var TRISB.4 ' SD card detect direction
SDO Var PORTC.7 ' SPI data out
SDO_TRIS Var TRISC.7 ' SPI data out direction
But I want to move the pins off from PortB.
Thanks and regards,
tacbanon
Re: Counting led blinks..
What errors are you getting?
Serout2 PORTC.6, 84, ["Init: ", Dec FAT_error, " ", Dec SDC_status, " ", Dec SDC_response, $d, $a]
Re: Counting led blinks..
Hi macrackit, I do not have any errors, I've been playing with it the whole night last night but no progress...
I also tried the following alias pins configurations from a book..(uising pic18F452) but no luck.
Code:
' Alias PIC pins and registers for SD/MMC card
SD_WE VAR PORTA.4 ' SD card write protect
SD_WE_TRIS VAR TRISA.4 ' SD card write protect direction
SDI VAR PORTC.5 ' SPI data in SD #7
SDI_TRIS VAR TRISC.5 ' SPI data in direction
SCL VAR PORTC.3 ' SPI clock SD #5
SCL_TRIS VAR TRISC.3 ' SPI clock direction
SD_CS VAR PORTC.2 ' SD card chip select SD #1
SD_CS_TRIS VAR TRISC.2 ' SD card chip select direction
SD_CD VAR PORTC.0 ' SD card detect
SD_CD_TRIS VAR TRISC.0 ' SD card detect direction
SDO VAR PORTC.4 ' SPI data out SD #2
SDO_TRIS VAR TRISC.4 ' SPI data out direction
Hmm..I don't understand, CS -> RB3, MOSI -> RC7, SCLK -> RB1 and MISO -> RB0 works fine without a problem, but assigning them to another port/pins giving me trouble.:)
(BTW I'm using Pic18F4550, crystal 20Mhz)
regards,
tacbanon
Re: Counting led blinks..
@mackrackit
Quote:
Serout2 PORTC.6, 84, ["Init: ", Dec FAT_error, " ", Dec SDC_status, " ", Dec SDC_response, $d, $a]
Hi, Sorry I spoke too soon, this is what I get when I'm trying to transfer to another port/pins "’nit: 6 2 0"
Re: Counting led blinks..
From the SDFS file, the 6 and 2 from the generated errors.
Quote:
CE_INIT_ERROR Con 6 ' An initialization error has occured
sdcCardNotInitFailure Con 2
From section 10.3 18F4550 data sheet.
Quote:
On a Power-on Reset, these pins, except
RC4 and RC5, are configured as digital
inputs. To use pins RC4 and RC5 as digi-
tal inputs, the USB module must be dis-
abled (UCON<3> = 0) and the on-chip
USB transceiver must be disabled
(UCFG<3> = 1).
And do you have the Capture / Compare turned off for PORTC?
Re: Counting led blinks..
Thanks for helping me out mackrackit..but I'm still having trouble running the following(I'm really sure if I'm getting the settings correctly).
Code:
Include "modedefs.bas"
asm
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm
DEFINE OSC 48
' Alias PIC pins and registers for SD/MMC card
SD_WE VAR PORTA.4 ' SD card write protect
SD_WE_TRIS VAR TRISA.4 ' SD card write protect direction
SDI VAR PORTC.5 ' SPI data in SD #7
SDI_TRIS VAR TRISC.5 ' SPI data in direction
SCL VAR PORTC.3 ' SPI clock SD #5
SCL_TRIS VAR TRISC.3 ' SPI clock direction
SD_CS VAR PORTC.2 ' SD card chip select SD #1
SD_CS_TRIS VAR TRISC.2 ' SD card chip select direction
SD_CD VAR PORTC.0 ' SD card detect
SD_CD_TRIS VAR TRISC.0 ' SD card detect direction
SDO VAR PORTC.4 ' SPI data out SD #2
SDO_TRIS VAR TRISC.4 ' SPI data out direction
' Include the SD/MMC subroutines (found in http://melabs.com/resources/samples/pbp/sdfs3.zip)
cnt var word
cnt = 0
Include "SDFS.PBP"
SDC_UseHardSPI = TRUE ' Use hardware SSP port for SPI.
ADCON1 = 15 ' All I/O pins digital
'--Added Pic settings
UCON.3 = 0 'USB module disabled
UCFG.3 = 1 'USB transceiver disabled
CCP1CON=0 ' Capture/Compare OFF
CCP2CON=0 '
Pause 100
' FSInit initializes the card and reads all the preliminary information from it
Gosub FSInit
Serout2 PORTC.6, 84, ["Init: ", Dec FAT_error, " ", Dec SDC_status, " ", Dec SDC_response, $d, $a]
If (FAT_error != 0) Then Stop
' This section defines a specific short (8.3) filename
' Note that spaces are use in empty elements and must be upper case for Windows
FAT_FileName[0] = "R"
FAT_FileName[1] = "E"
FAT_FileName[2] = "C"
FAT_FileName[3] = "O"
FAT_FileName[4] = "R"
FAT_FileName[5] = "D"
FAT_FileName[6] = "S"
FAT_FileName[7] = " "
FAT_FileName[8] = "T"
FAT_FileName[9] = "X"
FAT_FileName[10] = "T"
' Set file time to 8:30:10 and date to 1/1/2008
FAT_seconds = 5
FAT_minutes = 30
FAT_hours = 8
FAT_day = 1
FAT_month = 1
FAT_year = 28
' Open a file for write
FAT_mode = "A" ' Write mode
Gosub FSfopen ' Open file pointed to by Byte array FAT_FileName
Serout2 PORTC.6, 84, ["Open for write: ", Dec FAT_error, $d, $a]
If (FAT_error != 0) Then Stop
cnt = cnt + 5
' Write to file
FAT_src[0] = $30+cnt
FAT_src[1] = "M"
FAT_src[2] = "I"
FAT_src[3] = "C"
FAT_src[4] = "R"
FAT_src[5] = "O"
FAT_src[6] = "B"
FAT_src[7] = "O"
FAT_src[8] = "X"
FAT_src[9] = 13
FAT_src[10] = 10
FAT_count = 11
Gosub FSfwrite
Serout2 PORTC.6, 84, [ "Write ", Dec FAT_error, $d, $a]
If (FAT_error != 0) Then Stop
' Close file
Gosub FSfclose
Serout2 PORTC.6, 84, [ "Close ", Dec FAT_error, $d, $a]
End
Kindly check my hardware Connections
SDCARD MCU(4550)
CS ------ RC2
MOSI ------- RC5
SCK ------- RC3
MISO -------RC4
I'm not having a display in the terminal to identify the error produced, What do you think I'm missing?
Thanks in advance,
tacbanon
Re: Counting led blinks..
SDC_UseHardSPI = TRUE ' Use hardware SSP port for SPI.
Should be FALSE
Re: Counting led blinks..
That was it Dave, thank you for sharing your time...:)But I have another question, can I still make USB CDC with the setup we modified?regards,tacbanon
Re: Counting led blinks..
RC4 and RC5 are the USB pins.