Hi kerryzhou,
I am trying read register using the EzPort commands, specifically command Flash Read Data. The struct of this command is:
<code command(7:0)>,<address(23:00)>
The address of SIM Register that I want, it need 32 bits for its representations. In addition, the reference Manual of MK66FN2M0VMQ18 indicates that changes must be to made to the address maintain a width 24 bits.
Next, I show the function that I am using:
* @param addr Addres of register.
* @param data Param where store data.
* @param size Number data to read.
* @return EZ_RESULT_SUCCESS / EZ_RESULT_ERROR
*/
TEzResult ezSectorReadSIM(uint32_t addr, uint8_t *data, uint32_t size)
{
if( !data || !size ) return EZ_RESULT_ERROR;
if( size>4096 ) return EZ_RESULT_ERROR;
if( addr & 0xBFFB7F03) return EZ_RESULT_ERROR; //Valid Addres SIM UID
//Command EzPort Flahs Read Data.
wrBuf[0] = 0x03;
wrBuf[1] = (uint8_t)((addr >> 16) & 0xFF);
wrBuf[2] = (uint8_t)((addr >> 8) & 0xFF);
wrBuf[3] = (uint8_t)(addr & 0xFF);
// Sending of the command and Receive data.
if( ezSpiTransfer(wrBuf, rdBuf, 5+size) == EZ_RESULT_SUCCESS ){
memcpy(data, &rdBuf[4], size);
return EZ_RESULT_SUCCESS;
}
else {
return EZ_RESULT_ERROR;
}
}
