Raady Here
Full Member level 5
- Joined
- Jun 8, 2013
- Messages
- 242
- Helped
- 26
- Reputation
- 52
- Reaction score
- 26
- Trophy points
- 28
- Location
- India
- Activity points
- 1,571
PIC24EP512GP806
MPLAB8.8V
Hi,
I am interfacing s25FL032P flash memory with my pic through SPI. how to calculate and set SCK required to use.
For normal read mode in S25FL032P speed is 40Mhz clock speed. For setting prescalar bits in SPIxCON1 of PIC24 how do I calculate the what prescalar values i need to choose so that operation is at clock 40 Mhz.
I am using a oscillator 10 Mhz, clock init is
PLLFBD = 22; // M = 48
CLKDIVbits.PLLPOST = 0; // N1 = 2
CLKDIVbits.PLLPRE = 0; // N2 = 2
Fosc = Fin*(M/(N1*N2));
Fosc = 120 Mhz.
what are values to be set
SPI1CON1bits.SPRE = ; // Secondary prescalar bits.
SPI1CON1bits.PPRE = ; // Primary Prescalar bits.
many have taken 2:1 and 4:1 respectively , how do I know what is the sck ?
Regards,
Raady.
MPLAB8.8V
Hi,
I am interfacing s25FL032P flash memory with my pic through SPI. how to calculate and set SCK required to use.
For normal read mode in S25FL032P speed is 40Mhz clock speed. For setting prescalar bits in SPIxCON1 of PIC24 how do I calculate the what prescalar values i need to choose so that operation is at clock 40 Mhz.
I am using a oscillator 10 Mhz, clock init is
PLLFBD = 22; // M = 48
CLKDIVbits.PLLPOST = 0; // N1 = 2
CLKDIVbits.PLLPRE = 0; // N2 = 2
Fosc = Fin*(M/(N1*N2));
Fosc = 120 Mhz.
what are values to be set
SPI1CON1bits.SPRE = ; // Secondary prescalar bits.
SPI1CON1bits.PPRE = ; // Primary Prescalar bits.
many have taken 2:1 and 4:1 respectively , how do I know what is the sck ?
Code:
void Config_SPI(void)
{
SCK = 0; // SCK as output
SDO = 0; // SDO as output
SDI = 1; // SDI as input
WP = 0; // WP as O/P
//HOLD = 0; // HOLD as O/P
CS = 0; // CHIP SELECT as O/P
}
void Init_SPI(void)
{
Config_SPI(); // Configuration for SPI Modules.
// SPI Status Control Registers
SPI1STATbits.SPIEN = 0; // Disable the SPI Module.
SPI1STATbits.SPISIDL = 0; // Continue the Operation in Idle Mode.
SPI1STATbits.SRMPT = 0; // SPI shift register is not empty.
SPI1STATbits.SPIROV = 0; // No overflow has occured.
SPI1STATbits.SRXMPT = 0; // RX FIFO not empty
SPI1STATbits.SISEL = 3; // Buffer Interrupt Mode - Interrupt when SPI receive buffer is full.
SPI1STATbits.SPITBF = 0; // Transmit has started, SPIx transmit buffer is empty.
SPI1STATbits.SPIRBF = 0; // Receive is incomplete, SPIx Receive buffer is empty.
// SPI Control Regsiter 1
SPI1CON1bits.DISSCK = 0; // Internal SPI clock is enabled.
SPI1CON1bits.DISSDO = 0; // SDO is controller by module.
SPI1CON1bits.MODE16 = 1; // 1 - 16 bit , 0 - 8 bit mode
SPI1CON1bits.SMP = 1; // Input data is sampled at end of data output time.
SPI1CON1bits.CKE = 0; // Clock Edge Selected
SPI1CON1bits.SSEN = 0; // SSx pin is not used by module, pin is controller by port function.
SPI1CON1bits.CKP = 0; // Idle when clock is low level, active state is high level
SPI1CON1bits.MSTEN = 1; // Master Mode enable bits.
SPI1CON1bits.SPRE = 0; // Secondary prescalar bits.
SPI1CON1bits.PPRE = 0; // Primary Prescalar bits.
SPI1CON2bits.FRMEN = 0; // Framed SPI Support -> 1 - enabled, 0 - disabled.
/*
*/
}
Raady.
Last edited: