Hi Everyone,
I have 3 boards mikroMMB for PIC24 and I am developing a program and I need to read and write in the flash memory M25P80 that has on this board.
Somebody has a routine in BASIC to read and write this memory? I am looking the mikroeletronika web site but I didint find this routine to help me.
Somebody can help me?
Thank you in advanced
prof. Wagner
Flash memory module MikroMMB for PIC24
-
- Posts: 176
- Joined: 12 Aug 2007 01:33
Re: Flash memory module MikroMMB for PIC24
Hello,
if you have the 'mikroXXX PRO for dsPIC30/33 and PIC24'
you should find an flash-lib and the documentation in the help file.
My basic pro for pic & pic32 has it.
if you have the 'mikroXXX PRO for dsPIC30/33 and PIC24'
you should find an flash-lib and the documentation in the help file.
My basic pro for pic & pic32 has it.
Sometimes you can't see the forest for the trees.
-
- Posts: 126
- Joined: 25 Mar 2011 04:35
Re: Flash memory module MikroMMB for PIC24
Hi Hurtz Hurty,
Yes, I have the 'mikroXXX PRO for dsPIC30/33 and PIC24' compiler and I can see the flash lib, but these libs are to flash inside of the Microcontroller. These libs is to read and write in the flash of the code area of the microcontroller and I need to read and write the external flash model M25P80 that has on the board mikroMMB for PIC24. The other flash lib is to read and write devices like ADC, RTC and etc. I didnt find the lib to read and write in the flash memory like M25P80 or others memory.
Thanks your help
Prof. Wagner Ideali
Yes, I have the 'mikroXXX PRO for dsPIC30/33 and PIC24' compiler and I can see the flash lib, but these libs are to flash inside of the Microcontroller. These libs is to read and write in the flash of the code area of the microcontroller and I need to read and write the external flash model M25P80 that has on the board mikroMMB for PIC24. The other flash lib is to read and write devices like ADC, RTC and etc. I didnt find the lib to read and write in the flash memory like M25P80 or others memory.
Thanks your help
Prof. Wagner Ideali
-
- Posts: 176
- Joined: 12 Aug 2007 01:33
Re: Flash memory module MikroMMB for PIC24
Hello,
this is from the example folder for PIC32, should work ....
May be you have to comment out everything what belongs to the TFT.
this is from the example folder for PIC32, should work ....
May be you have to comment out everything what belongs to the TFT.
Code: Select all
' *
' * Project name:
' SerialFlash example (Demonstration of usage of the SerialFlash board)
' * Copyright:
' (c) MikroElektronika, 2011.
' * Revision History:
' 20110511(TL):
' - initial release;
' * Description:
' Demonstration of SerialFlash usage (chip erase, read Flash ID, simple writing and reading back a simple byte,
' simple writing and reading back an array of 16 bytes).
' * Test configuration:
' MCU: P32MX460F512L
' http://ww1.microchip.com/downloads/en/DeviceDoc/61143G.pdf
' Dev.Board: LV32MX v6 hw.rev.1.10 - ac:Serial_Flash
' http://www.mikroe.com/eng/products/view/462/lv-32mx-v6-development-system/
' Oscillator: XT-PLL, 80.0000MHz
' Ext. Modules: On board Serial Flash
' SW: mikroBasic PRO for PIC32
' http://www.mikroe.com/eng/products/view/624/mikrobasic-pro-for-pic32/
' * NOTES:
' - none.
' *
program Serial_Flash
include Serial_Flash_driver
const _DATA_ARRAY_SIZE as word = 16
' TFT display connections
dim TFT_DataPort as char at LATE
TFT_DataPort_Direction as char at TRISE
TFT_RST as sbit at LATC1_bit
TFT_BLED as sbit at LATD2_bit
TFT_RS as sbit at LATB15_bit
TFT_CS as sbit at LATF12_bit
TFT_RD as sbit at LATD5_bit
TFT_WR as sbit at LATD4_bit
TFT_RST_Direction as sbit at TRISC1_bit
TFT_BLED_Direction as sbit at TRISD2_bit
TFT_RS_Direction as sbit at TRISB15_bit
TFT_CS_Direction as sbit at TRISF12_bit
TFT_RD_Direction as sbit at TRISD5_bit
TFT_WR_Direction as sbit at TRISD4_bit
' End TFT module connections
dim CS_Serial_Flash_bit as sbit at LATB9_bit
CS_Serial_Flash_Direction_bit as sbit at TRISB9_bit
sub procedure PMPWaitBusy()
while(PMMODE.BUSY = 1)
nop
wend
end sub
sub procedure SetIndex(dim index as byte)
TFT_RS = 0
PMDIN = index
PMPWaitBusy()
end sub
sub procedure WriteCommand(dim cmd as byte)
TFT_RS = 1
PMDIN = cmd
PMPWaitBusy()
end sub
sub procedure WriteData(dim _data as word)
TFT_RS = 1
PMDIN = _data
PMPWaitBusy()
end sub
sub procedure TFT_In()
AD1PCFG = 0xFFFF
PCFG12_bit = 0
PCFG13_bit = 0
' PMP setup
PMMODE = 0
' PMAEN: Parallel Master Port Address Enable Register
PMAEN = 0
PMCON = 0 ' WRSP: Write Strobe Polarity bit
' 0 = Read strobe active-low (PMWR) - 0 is set by reset
PMMODE = 0
PMAEN = 0
PMCON = 0
PMMODE = 0x0604
PMCON = 0x8300
TFT_Set_Active(@SetIndex,@WriteCommand,@WriteData)
TFT_Rotate_180(1)
TFT_Init(320, 240)
end sub
dim
write_array as byte[_DATA_ARRAY_SIZE]
read_array as byte[_DATA_ARRAY_SIZE]
temp, SerialFlashID, i, to_write, success as byte
txt as string[12]
address as longword
half_address as word
main:
TFT_In()
TFT_Fill_Screen(CL_AQUA)
SPI2_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 1, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE)
SerialFlash_init()
SerialFlash_WriteEnable()
Delay_ms(500)
TFT_Write_Text("***Serial Flash Demo***", 70, 15)
'************************************************************************
'* Erase entire flash
'************************************************************************/
TFT_Write_Text("Erasing chip... ", 110, 45)
SerialFlash_ChipErase()
TFT_Write_Text("Done!", 110, 65)
'************************************************************************
'* Read Flash ID
'************************************************************************/
SerialFlashID = SerialFlash_ReadID()
ByteToStr(SerialFlashID, txt)
TFT_Write_Text("Flash ID:", 110, 95)
TFT_Write_Text(txt, 180, 95)
Delay_ms(500)
'************************************************************************
'* Write and read back a single byte
'************************************************************************/
temp = 221
TFT_Write_Text("Writting:", 110, 125)
ByteToStr(temp, txt)
TFT_Write_Text(txt, 180, 125)
SerialFlash_WriteByte(temp, 0x123456)
TFT_Write_Text("Reading: ", 110, 145)
temp = SerialFlash_ReadByte(0x123456)
ByteToStr(temp, txt)
TFT_Write_Text(txt, 180, 145)
Delay_ms(500)
'************************************************************************
'* Write the repetitive pattern of data to fill the first 4K of memory
'* and then read the entire flash again and check the data correctness
'************************************************************************/
TFT_Write_Text("Writing array...", 110, 175)
SerialFlash_WriteArray(0x0000, @write_array, _DATA_ARRAY_SIZE)
Delay_ms(500)
TFT_Write_Text("Reading array...", 110, 195)
SerialFlash_ReadArray(0x0000, @read_array, _DATA_ARRAY_SIZE)
Delay_ms(500)
success = 1
for i = 0 to _DATA_ARRAY_SIZE -1
if (read_array[i] <> write_array[i]) then
success = 0
break
end if
next i
if (success = 1) then
TFT_Write_Text("Success - Full match!", 110, 215)
else
TFT_Write_Text("Failed", 110, 215)
end if
end.
Sometimes you can't see the forest for the trees.
- slavisa.zlatanovic
- mikroElektronika team
- Posts: 1321
- Joined: 07 Apr 2009 09:39
Re: Flash memory module MikroMMB for PIC24
Hi Prof.Wagner!
Please, follow this link and find mikroMMB for PIC24 Board demo examples:
http://www.mikroe.com/eng//eng/download ... mikroc.zip
Serial Flash example is what you're looking for.
Please, follow this link and find mikroMMB for PIC24 Board demo examples:
http://www.mikroe.com/eng//eng/download ... mikroc.zip
Serial Flash example is what you're looking for.
Best regards
Slavisa
Slavisa
-
- Posts: 126
- Joined: 25 Mar 2011 04:35
Re: Flash memory module MikroMMB for PIC24
Thank you Hurtz Hurty and Slavisa.Zlatanovic
I will test it now.
prof. Wagner
I will test it now.
prof. Wagner
-
- Posts: 126
- Joined: 25 Mar 2011 04:35
Re: Flash memory module MikroMMB for PIC24
Hi Slavisa.Zlatanovic
1-The example that Hurtz Hurty showed didnt work, I change the Pin out to MikroMMB for PIC24, but it didnt work.
2-The example in C for MikroMMB for PIC24 there is something wrong, because in the schematic that I recieved from MikroEletronika the SCK2,SDI2 and SDO2 is pin out of pic 10,11 and 12, but in the C example has a instructions to change the pin out to 21,26 and 19, you can see below, I extract the PPS_Mapping from the program. What is correct the schematic or this program? Why these instruction in the program if the SPI 2 is in the pin out 10,11 and 12?
PPS_Mapping(19, _OUTPUT, _SDO2);
PPS_Mapping(21, _OUTPUT, _SCK2OUT);
PPS_Mapping(26 ,_INPUT, _SDI2);
3-In the program there isnt any instruction to acess to SPI memory. You can see below the read function that I extract from the program. How this routine works? is where the instruction to read the data from the memory?
Sorry my questions, but the compiler has the instruction like SPI2_read() or SPI2_write() and I dont see these instruction in this examples.
'************************************************************************
'* Function SerialFlash_ReadByte()
'* -----------------------------------------------------------------------
'* Overview: Function that reads the byte from the address
'* Input: address to be read
'* Output: byte data from the address
'************************************************************************
sub function SerialFlash_ReadByte(dim address as longword) as byte
dim temp as byte
CS_Serial_Flash_bit = 0
SPI_Wr_Ptr(_SERIAL_FLASH_CMD_READ)
SPI_Wr_Ptr(Higher(address))
SPI_Wr_Ptr(Hi(address))
SPI_Wr_Ptr(Lo(address))
temp = SPI_Rd_Ptr(0)
CS_Serial_Flash_bit = 1
result = temp
end sub
Thanks your help.
Prof. Wagner Ideali
1-The example that Hurtz Hurty showed didnt work, I change the Pin out to MikroMMB for PIC24, but it didnt work.
2-The example in C for MikroMMB for PIC24 there is something wrong, because in the schematic that I recieved from MikroEletronika the SCK2,SDI2 and SDO2 is pin out of pic 10,11 and 12, but in the C example has a instructions to change the pin out to 21,26 and 19, you can see below, I extract the PPS_Mapping from the program. What is correct the schematic or this program? Why these instruction in the program if the SPI 2 is in the pin out 10,11 and 12?
PPS_Mapping(19, _OUTPUT, _SDO2);
PPS_Mapping(21, _OUTPUT, _SCK2OUT);
PPS_Mapping(26 ,_INPUT, _SDI2);
3-In the program there isnt any instruction to acess to SPI memory. You can see below the read function that I extract from the program. How this routine works? is where the instruction to read the data from the memory?
Sorry my questions, but the compiler has the instruction like SPI2_read() or SPI2_write() and I dont see these instruction in this examples.
'************************************************************************
'* Function SerialFlash_ReadByte()
'* -----------------------------------------------------------------------
'* Overview: Function that reads the byte from the address
'* Input: address to be read
'* Output: byte data from the address
'************************************************************************
sub function SerialFlash_ReadByte(dim address as longword) as byte
dim temp as byte
CS_Serial_Flash_bit = 0
SPI_Wr_Ptr(_SERIAL_FLASH_CMD_READ)
SPI_Wr_Ptr(Higher(address))
SPI_Wr_Ptr(Hi(address))
SPI_Wr_Ptr(Lo(address))
temp = SPI_Rd_Ptr(0)
CS_Serial_Flash_bit = 1
result = temp
end sub
Thanks your help.
Prof. Wagner Ideali
- slavisa.zlatanovic
- mikroElektronika team
- Posts: 1321
- Joined: 07 Apr 2009 09:39
Re: Flash memory module MikroMMB for PIC24
Hi!
See the datasheet for more details.
It is the convenient way to make your code easier to port among different architectures.
When you do SPI2_Init() then SPI_Rd_Ptr and SPI_Wr_Ptr initialize and correspond to SPI2_Read and SPI2_Write.
Note that the number in the PPS_Mapping(19, _OUTPUT, _SDO2); corresponds to the RP19 pin and not the (ordinal) pin number.2-The example in C for MikroMMB for PIC24 there is something wrong, because in the schematic that I recieved from MikroEletronika the SCK2,SDI2 and SDO2 is pin out of pic 10,11 and 12, but in the C example has a instructions to change the pin out to 21,26 and 19, you can see below, I extract the PPS_Mapping from the program. What is correct the schematic or this program? Why these instruction in the program if the SPI 2 is in the pin out 10,11 and 12?
PPS_Mapping(19, _OUTPUT, _SDO2);
PPS_Mapping(21, _OUTPUT, _SCK2OUT);
PPS_Mapping(26 ,_INPUT, _SDI2);
See the datasheet for more details.
Note that we've used the SPI_Rd_Ptr and SPI_Wr_Ptr instead of SPI2_Read and SPI2_Write routines.3-In the program there isnt any instruction to acess to SPI memory. You can see below the read function that I extract from the program. How this routine works? is where the instruction to read the data from the memory?
Sorry my questions, but the compiler has the instruction like SPI2_read() or SPI2_write() and I dont see these instruction in this examples.
It is the convenient way to make your code easier to port among different architectures.
When you do SPI2_Init() then SPI_Rd_Ptr and SPI_Wr_Ptr initialize and correspond to SPI2_Read and SPI2_Write.
Best regards
Slavisa
Slavisa
-
- Posts: 126
- Joined: 25 Mar 2011 04:35
Re: Flash memory module MikroMMB for PIC24
Hi Slavisa.Zlatanovic
Now the program is running ok.
I made some mistake, what you informed me was ok and now everything is ok.
Thank you a lot
Prof. Wagner
Now the program is running ok.
I made some mistake, what you informed me was ok and now everything is ok.
Thank you a lot
Prof. Wagner