2015-12-09 10:15 AM
Hi
I am writing some data to an external device on the address and data bus I have used Stm32cube to set up the timing data. Once I have written the data to the device I have to strobe a data line. This is fine but the processor does not behave as I would expect. I would expect the write command to complete before the processor moves on the the next command (strobing the data line) but it appears to cache the write and continue to process the rest of the code. So How can I ensure the write is complete (ie chip select line going high) before the processor moves on to the next instruction. I could use a delay but there must be a way in the processor to tell it to wait or a register I can poll to see if it is complete? Thanks John. Setup code /** Perform the SRAM2 memory initialization sequence */ hsram2.Instance = FMC_NORSRAM_DEVICE; hsram2.Extended = FMC_NORSRAM_EXTENDED_DEVICE; /* hsram2.Init */ hsram2.Init.NSBank = FMC_NORSRAM_BANK2; hsram2.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE; hsram2.Init.MemoryType = FMC_MEMORY_TYPE_SRAM; hsram2.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_8; hsram2.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE; hsram2.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW; hsram2.Init.WrapMode = FMC_WRAP_MODE_DISABLE; hsram2.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS; hsram2.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE; hsram2.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE; hsram2.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE; hsram2.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE; hsram2.Init.WriteBurst = FMC_WRITE_BURST_DISABLE; hsram2.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY; /* Timing */ Timing.AddressSetupTime = 15; Timing.AddressHoldTime = 15; Timing.DataSetupTime = 255; Timing.BusTurnAroundDuration = 15; Timing.CLKDivision = 16; Timing.DataLatency = 17; Timing.AccessMode = FMC_ACCESS_MODE_A; /* ExtTiming */ HAL_SRAM_Init(&hsram2, &Timing, NULL); #define DDS1_PIRA0 (*(volatile unsigned char*) (0x64000000)) #define DDS1_PIRA1 (*(volatile unsigned char*) (0x64000001)) Main code DDS1_PIRA0 = 0x00; // write to external device at DDS1_PIRA1 = 0xFF; HopClk2On(); // Toggle external port bit - This is being set high while the CS signal is still low - WHY HAL_Delay(1); HopClk2Off();2015-12-09 03:48 PM
Try to read back.
JW2015-12-10 01:26 AM
Thanks for the reply, but the device is write only - which makes life interesting
2015-12-10 02:44 AM
It's OK - you don't need to check whether the value has been written matches the readback value. The readback is to ensure that the write has completed - the mcu won't reorder the accesses.
JW2015-12-10 06:28 AM
Great, That worked a treat. As the device was write only I didn't think to try a read, some times you over look the easy solutions. Thanks again.