How to co-exist SD/MMC and I2C module - PowerPoint PPT Presentation

About This Presentation
Title:

How to co-exist SD/MMC and I2C module

Description:

Title: PowerPoint Presentation Last modified by: momose Created Date: 1/1/1601 12:00:00 AM Document presentation format: Other titles – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 20
Provided by: momoseComh
Category:
Tags: i2c | mmc | exist | layer | module

less

Transcript and Presenter's Notes

Title: How to co-exist SD/MMC and I2C module


1
How to co-exist SD/MMC and I2C module
MCU
SD/MMC
SCK/SCL
SDI/SDA
SDO
CE
I2C Device
2
Typ 65mA
PIC 18F2550
GPS Module
SD
Soft UART
SPI
LCD
Soft I2C
Boost DC/DC
2X AA Cell
VCC(3.3V)
3
Tips to handle SD card
Initialize at PWON
Entering SPI mode
Csclkdi ? high
/CS?high Send dummy 80 clocks (Send 0xff x
10) /CS?Low Send 0x40,0x00,0x00,0x00,0x00,0x95 Ret
GetResponse() While(ret0x0) cs?high send
0xff cs?low send 0x40,0x00,0x00,0x00,0x00,0x00
,0x95 retGetResponse() /cs?high Send
0xff Status
Raw I/O
B7
B6
DO
B7
B6
DI
CLK
GetResponse
Ret?0xff Do retry send 0xff if(!(res0xfe)
break Return ret
4
Tips to handle SD card addressd read /write
DI
A3
A2
A1
A0
0x4017
Command 17
5
Least command list
6Bytes command
Start Command Argument CRC Stop
01 6bit 32bit 7bit 1
CRC Required at CMD0 before changing SPI
mode. Ignored at SPI mode.
Response R1 (1Byte)
Fixed Invalid argument Invalid address Erase err CRC Err Invalid CMD ? Idling
0 1/0 1/0 1/0 1/0 1/0 1/0 1/0
Command Arg Response Operation / affects
CMD0 none R1 Reset card
CMD1 None R1 Ask if card reset has done?
CMD16 Length R1 Change block length used in CMD 17 and CMD24.Default is 512.Up to 2024 bytes.Some restrictions depend on the card. Does not apply on write operation.
CMD17 Address R1 Single block read.
CMD24 Address R1 Single block write
6
Single block read sequence
/CS
TX
CMD16
A3
A2
A1
A0
FF
RX

R1
D0
D1
D511
CRC1
CRC2
Single block write sequence
/CS
TX

CMD24
A3
A2
A1
A0
FF
D0
D1
D511
R1
CRC1
CRC2
7
Single block read sequence
Regular task
1s Timer invocation.
Read SW.
Read and Parse GPS Msg.
Read Batt. Volt.
Write data to SD.
Exec command
Update LCD.
Software I2C Driver
FAT16 Filesystem
Software UART Driver
8
Software I2C
Interrupt
Timer Value
Consider benefits between Direct execution and
ISR interruption. MAX clk freq 400kHz
2.5us Exec step _at_ 8MHz 0.5us
_at_40MHz ... 0.1us Interrupt latency several clks
NOP
SCL
SDA
NOP blank
b7
b6
ACK S?M
START
state
ST
PAYLOAD
ACK
data
clk
9
Timer assignment
TMR0
Software serial
TMR1
Software I2C
TMR2
TMR3
10
Software serial (receive only)
top level interface
Underlying i/o func in ISR if RXING process
RX until done else if HAS_TX process TX
until done else wait for RX
RX buff
char ser_getchar(void)
State diagram
INIT
waiting for start bit TMR0L ? 0xff //TMR0 full
count T0IF?0 // Clear TMR0 flag T0IE?1 // Set
TMR0 INT
RXWAITING
TXSTBY
ser_getchar()
RXBUSY
TXBUSY
Tx not implimented
RXREADY
RXERR
b
1.5b
LSB FIRST
1
2
3
4
5
6
SP
ST
0
7
RXWAITING
RXBUSY
RXREADY
11
Software serial timing consideration
interrupt read bit prepare for next
Counter value for Start BIT 1.5bit 1.563E-4s
... 195.38 256 195 61 Other BIT 1bit
1.042E-4s ... 124.8 256 125 131
1/9600 1.042E-4s
ST
1.5bit
1/8
1/2
1us
8bit Timer (1/256)
2MHz
1MHz
104.17us
1/4
8MHz
Prescaler
10MHz
40MHz
1.25MHz 0.8us
1/104
1/130
12
SPI raw level I/O
13
MBR
0
boot
struct Byte bootDescriptor /
0x80 bootable device, 0x00 non-bootable / Byte
firstPartitionSector3 / 1st sector
number / Byte fileSystemDescriptor /
1FAT12, 4FAT16(less than 32MB), 5?? DOS
???????,
6FAT16(more 32MB), 0xbFAT32(more 2GB),
0xcFAT32 Int32h
??, 0xeFAT16 Int32h ??,
0xf?? DOS ???????? Int32h ??
/ Byte lastPartitionSector3 Byte
firstSectorNumbers4 / first sector
number (link to BPB sector) / Byte
numberOfSectors4 partitionTable
446
P.tbl1
P.tbl2
P.tbl3
P.tbl4
firstSectorNumbers(454457) holds offset to
logical sector 0 in little endian
signature
  • ex 3E 00 00 00
  • 3E 512 7C00

PBR
7C00
JMP INST(3)
struct Byte bytesPerSector2 /
bytes/sector / Byte sectorsPerCluster
/ sectors/cluster / Byte reservedSectors2
/ reserved sector, beginning with sector 0
/ Byte numberOfFATs / file
allocation table / Byte rootEntries2
/ root entry (512) / Byte totalSectors2
/ partion total secter / Byte
mediaDescriptor / 0xf8 Hard Disk
/ Byte sectorsPerFAT2 / sector/FAT
(FAT32 always zero see bigSectorsPerFAT) / Byte
sectorsPerTrack2 / sector/track (not
use) / Byte heads2 / heads
number (not use) / Byte hiddenSectors4
/ hidden sector number / Byte
bigTotalSectors4 / total sector number
/ FAT16BPB
OEM NAME (8)
BIOS Param Blk(25)
Ext BIOS Param Blk(26)
Boot (448)
signature(2)
14
PBR ReservedSectors x 512 ex 7C00h 6x512
8800h
8800
FAT1
SectorsPerFat
ex F5h x 5121EA00h 8800h1EA00h 27200h
27200
FAT2
ex 27200h1EA00h 45C00h
sizeof(Direntey) x rootEntries ex 32 x 512
16384 45C00h 16384(dec)
45C00
Root directory entry
typedef struct DirEntry_t Byte name8
/ file name / Byte
extension3 / file name extension /
Byte attribute / file attribute
bit 4
directory flag
bit 3 volume flag
bit 2 hidden flag
bit 1 system flag
bit 0 read only flag
/ Byte reserved / use NT or
same OS / Byte createTimeMs /
VFAT ??????????????10??? (0 199) / Byte
createTime2 / VFAT ????????????? /
Byte createDate2 / VFAT ?????????????
/ Byte accessDate2 / VFAT
??????????????? / Byte
clusterHighWord2 / FAT32 ?????????????? 16
bits / Byte updateTime2 Byte
updateDate2 Byte cluster2 /
start cluster number / Byte fileSize4
/ file size in bytes (directory is always
zero) /
49C00
User Data Area
15
Filesystem initialization
  • Retrieve firstSectorNumbers
  • Determine head of PBR1 ? firstSectorNumbers x 512
  • Note We does not handle other than No.1 Partition.

Read MBR
  • Retrieve ReservedSectors, SectorsPerFAT,
    SectorsPerCluster, rootEntries, bigTotalSectors
  • Determine head address of FAT1 ? PBR1
    ReservedSectors x 512

  • FAT2 ? FAT1 SectorsPerFAT x 512
  • RDE
    ? FAT2 SectorsPerFAT x 512
  • UDA
    ? RDE 32 x rootEntries
  • NumSectorsOfUDA ? bigTotalSectors
    ReservedSectors (UDA FAT1)/512
  • UDAClusters ? NumSecdtorsOfUDA /
    SectorsPerCluster
  • Holds following information

Read PBR1
FAT1
FAT2
SectorsPerFAT
RDE
rootEntries
UDA
UDAClusters
SectorsPerCluster
16
Create and write a file on filesystem
RDE
FAT1
FAT2
UDA
Create()
R
Look for unused RDE
R
Look for unused cluster
W
Mark 0xFF to found cluster
W
W
Update corresponding RDE
Write()
W
Write Data to allocated cluster
W
Update length of RDE
W
Update linked list of FAT (if data occupies
beyond current cluster)
W
close()
Flush unwritten data
Update length of RDE
Mark 0xFF to last used cluster
17
Interface layer
ser_init()
gps_init()
GPS status register
i2c_init()
ser_getchr()
gps_parse()
ser_isr()
coord
buff
buff
LCD Display
i2c_write()
time
info
fopen()
mm_init()
fclose()
adc_read()
V.Batt
spi_init()
mm_read_block()
V.BATT
SD Card
fwrite()
spi_trx()
mm_write_block()
fprintf()
SW
SPI
MM
FAT
18
write(data, length)
buff_len
buffer512
cluster
sector
  • current_cluster
  • index of sector in the curr. cluster
  • address ?
  • uda (curr.cluster -2)
  • sector_per_cluster 512
  • index_of_sector 512
  • buff_len

uda
19
GPS Data format of GGA
N?North S?South
Time in UTC where hh?hour mm?min ss.sss?sec
Altitude where dd? deg mm.mmmm ?
min(resolution 1E-4)
Longitude where ddd? deg mm.mmmm ?
min(resolution 1E-4)
W?West E?East
GPGGA,hhmmss.sss,ddmm.mmmm,N,dddmm.mmmm,E, v,ss
,dd.d,hhhhh.h,M,gggg.g,M,XXX.X,0000hhltCRgtltLFgt
2
13
23
25
36
0
38
40
48
56
Latitude
Latitude unit in meter
Num of STAs used range 00 - 12
State of measuring where 0?Not working
1?Working
Write a Comment
User Comments (0)
About PowerShow.com