[RESOLVED]EasyAVR5 with external sd card

General discussion on mikroBasic for AVR.
Post Reply
Author
Message
emule
Posts: 22
Joined: 17 Aug 2008 00:15

[RESOLVED]EasyAVR5 with external sd card

#1 Post by emule » 29 Oct 2008 16:30

hi,

when i use connector sd card integrated to easyavr5 the code follow work but when i use connector sd card external connected to PORTB it don't work

SW7 and SW8 are off because i use directly PORTB connected to sd card external.

PORTB.4 = CS
PORTB.5 = MOSI
PORTB.6 = MISO
PORTB.7 = SS (SCK)

Code: Select all

program sd1

dim   filename     as string[14]
dim   filetmp      as string[512]
dim   ret          as byte

sub procedure createFile
    dim   i          as word


    Mmc_Fat_Assign(filename, 0x80)     ' Will not find file and then create file
    Mmc_Fat_Rewrite                    ' To clear file and start with new data
    for i = 0 to 1023
        filetmp[i] = "A"
    next i
    Mmc_Fat_Write(filetmp, 1024) ' write data to the assigned file
end sub

main:
  DDRB = DDRB and $A0
  DDRB = DDRB or  $BF

  Glcd_Init(PORTD, 2, 3, 4, 5, 7, 6, PORTC)
  Glcd_Set_Font(font5x7,5,8,32)
  Glcd_Fill($00)

  filename = "IMAGE001TXT"

  ret = Mmc_FAT_Init(PORTB,4)
  if ret = 0 then
    Glcd_Write_Text("Initialization OK",6,1,1)
  else
    Glcd_Write_Text("InitError",6,1,1)
  end if

  Glcd_Write_Text("Writing file",6,2,1)
  createFile
  Glcd_Write_Text("Write ok",6,3,1)




end.
the connector external with SD CARD (2go) is ok with bascom avr.
the connector external is a pcb from a dvd player but is ok because is ok from bascom avr connected to portb.

any idea ?
Last edited by emule on 01 Nov 2008 21:07, edited 1 time in total.

emule
Posts: 22
Joined: 17 Aug 2008 00:15

#2 Post by emule » 29 Oct 2008 19:04

any suggestion ?

emule
Posts: 22
Joined: 17 Aug 2008 00:15

#3 Post by emule » 30 Oct 2008 19:43

i have tested this code too and it don't work

i have atmega32 8mhz

Code: Select all

program mmc_on_glcd2
dim i, k,tmp as byte
data_array as byte[16]
str1 as string[2]
sectormmc as longint
data_sector as byte[512]
j as word


sub procedure printbyte (dim byref bb as byte, dim l,c as byte)
dim str2 as string[2]
ByteToHex(bb, str2)
Glcd_Write_Text(str2,l,c,1)
end sub

sub procedure read_spi_reg (dim c as byte)
tmp = SPCR
printbyte(tmp, 0,c)
tmp = SPSR
printbyte(tmp, 15,c)
tmp = SPDR
printbyte(tmp, 30,c)
end sub

sub procedure initsd
'to prevent the bug in the fat library
    spcr=$50
    read_spi_reg (0)
    PORTB.4 = 0 'CS low

    PORTB.4 = 1 'CS high
    for i = 0 to 9
        spdr=$FF
        while spsr=0
        wend
    next i
    PORTB.4 = 0 'CS low
    printbyte(spdr,70,0)
end sub


main:

'DDRB = $BF
'DDRB.7 = 1 ' SCK output
'DDRB.6 = 0 ' MISO input
'DDRB.5 = 1 ' MOSI output
'DDRB.4 = 1 ' SS output
  
Glcd_Init(PORTD, 2, 3, 4, 5, 7, 6, PORTC)
Glcd_Set_Font(font5x7,5,8,32)
Glcd_Fill(0x00)

DDRB = DDRB and $A0
DDRB = DDRB or $BF


initsd


'Mikroelktronika's stuff now
i = Mmc_Init(PORTB, 4)
if i = 0 then
   Glcd_Write_Text("Initialization OK",6,1,1)
else
    Glcd_Write_Text("InitError",6,1,1)
end if

i = MMC_Read_CID(data_array)
if i = 0 then
Glcd_Write_Text("CID number",35,2,1)
for k = 0 to 15
ByteToHex(data_array[k], str1)
Glcd_Write_Text(str1,8+k*6,3,1)
next k
else
Glcd_Write_Text("CID Error",35,3,1)
end if
' CSD
i = MMC_Read_CSD(data_array)
if i = 0 then
Glcd_Write_Text("CSD number",35,4,1)
for k = 0 to 15
ByteToHex(data_array[k], str1)
Glcd_Write_Text(str1,8+k*6,5,1)
next k
else
Glcd_Write_Text("CSD Error",35,5,1)
end if
'end of 'Mikroelktronika's stuff

'Read the sector 0
'With FAT16, the sector 0 must be :
'EB3C904D53444F53352E...
sectormmc=0
for j= 0 to 511 ' initialize the buffer
data_sector[j]=$00
next j

i = Mmc_Read_Sector(sectormmc, data_sector) ' reading...
ByteToHex(data_sector[k], str1) ' transform byte into string

for k = 0 to 9 ' display the string
ByteToHex(data_sector[k], str1)
Glcd_Write_Text(str1,0+k*12,6,1)
next k
glcd_write_text("EB3C904D53444F53352E",0,7,1)



end.

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Re: [EasyAVR5] external sd card

#4 Post by Thomas.Pahl@t-online.de » 30 Oct 2008 20:33

when i see it right, cs-pin of sd-card on mikroe board is connected to B.2
Thopas

emule
Posts: 22
Joined: 17 Aug 2008 00:15

#5 Post by emule » 30 Oct 2008 22:29

i use easyavr5 but i don't use sd card from easyavr5, i use breakout sd card connected to pin

PORTB.4 CS
PORTB.5 MOSI
PORTB.6 MISO
PORTB.7 SCK

emule
Posts: 22
Joined: 17 Aug 2008 00:15

#6 Post by emule » 31 Oct 2008 03:11

when i use i = MMC_Init(PORTB,6)

the CID and CSD are ramdom number.

SW7 are all off excepted PB4 for MISO
SW8 are all off excepted PB6 for CS
SW8 PB5 for MOSI is off
SW8 PB7 for SCK is off

i don't understand

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

#7 Post by Thomas.Pahl@t-online.de » 31 Oct 2008 14:44

I meant breakoutboard from mikroe. It uses CS = PortB.2 .
Thopas

emule
Posts: 22
Joined: 17 Aug 2008 00:15

#8 Post by emule » 31 Oct 2008 19:30

CS = PORTB.2
MOSI = PORTB.3
MISO = PORTB.4
SCK = PORTB.5

it's that ?

emule
Posts: 22
Joined: 17 Aug 2008 00:15

#9 Post by emule » 31 Oct 2008 19:37

How I have to positioning switch SW2, SW7 and SW8 ?

thanks in advance

emule
Posts: 22
Joined: 17 Aug 2008 00:15

#10 Post by emule » 31 Oct 2008 20:53

Thopas wrote:I meant breakoutboard from mikroe. It uses CS = PortB.2 .
Thopas
is not breakout board from mikroe, is breakout bord from dvd player that attempt to connect in portb from easyavr5a

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

#11 Post by Thomas.Pahl@t-online.de » 01 Nov 2008 16:04

To disconnect internal sd-card: SW7 1-8 off, SW8 1-7 off.
SW2 : for those pins of Port B you connect to sd-card of course off.
I do not know about that board from your dvd-player but it must look very alike that from mikroe - else do not connect to easyavrboard. Specially it should have voltage deviders for the data and clock pins and of course 3V regulator for supply. Compare schematic of sd-card-board on mikroe.com.
MOSI = PB5 connect to sd-card data out
MISO = PB6 connect to sd-card data in
SCK = PB7 connect to sd-card clock in
cs pin of sd-card connect to any port pin specially that you use in your code PB4 will do.
Nothing new - but perhaps helps.
Thopas

emule
Posts: 22
Joined: 17 Aug 2008 00:15

#12 Post by emule » 01 Nov 2008 20:16

may be my breakout sdcard do not support sd card 2go

emule
Posts: 22
Joined: 17 Aug 2008 00:15

[RESOLVED]

#13 Post by emule » 01 Nov 2008 21:06

its ok now, it was because the sd card 2go is not recognize , i have tested with card 512 mo and is ok

thank you.

Post Reply

Return to “mikroBasic for AVR General”