Project: SPI_MSTransfer

Yeah - abandon the CS code - once I counted the interrupts 2 CS fpr 1 spoi0 it was not only solving the wrong problem - but not in a better way.

Both my MST systems running since noted - NO ERRORS.
 
No - that misconception was corrected in prior posts - in one case re-reading that was V16 used in earlier posts to good end and then when isr() hit rate was counted.

Did you figure out a way handle the isr queue separate from the user's Master push queue?

Need to add the FULL_SPEW but instrumented F&F messages as well as the DEBUGHACK version as distinct F&F messages for the Master to send and the Slave to handle distinct from the True TViewer messages.

Tony: If you want to make an MST V_0.1.0 version with the working F&F code and the #ifdef{serial} we can make that the current basis for the other thread. That thread doesn't have urgent need for Slave Push.
 
this must be some fluke thing but...
im letting this run at 50ms slave -> master transfers, with a little details...


slave transfer16 method mod:

Code:
    __disable_irq();
    teensy_stm_queue.push_back(_vector);
    //      if ( teensy_stm_queue.size() > 14 ) teensy_stm_queue.pop_front();
    spi0_isr();
    __enable_irq();
    NVIC_SET_PRIORITY(IRQ_SPI0, 0); // set priority
    NVIC_ENABLE_IRQ(IRQ_SPI0); // enable CS IRQ

reason why something is fishy, but working?... as a trick first i disable the interrupts
immediately after queuing a slave's payload, i call the spi0_isr directly, in case it missed a "fire" while disabled (this aparently stopped most errors!?) (it will exit if nothing to do)
next i reenabled interrupts
but the thing is, eventually it will crash again, so i tested with resetting the SPI NVIC priority
what the heck!? its still going?!?
does disabling/reenabling interrupts reset the IRQ's???????????????????????????
Code:
1892.00,61893.00,61894.00,61895.00,61896.00,61897.00,61898.00,61899.00,61900.00,61901.00,61902.00,61903.00,0
61904.00,61905.00,61906.00,61907.00,61908.00,61909.00,61910.00,61911.00,61912.00,61913.00,61914.00,61915.00,0
61916.00,61917.00,61918.00,61919.00,61920.00,61921.00,61922.00,61923.00,61924.00,61925.00,61926.00,61927.00,0
61928.00,61929.00,61930.00,61931.00,61932.00,61933.00,61934.00,61935.00,61936.00,61937.00,61938.00,61939.00,0
61940.00,61941.00,61942.00,61943.00,61944.00,61945.00,61946.00,61947.00,61948.00,61949.00,61950.00,61951.00,0
61952.00,61953.00,61954.00,61955.00,61956.00,61957.00,61958.00,61959.00,61960.00,61961.00,61962.00,61963.00,0
61964.00,61965.00,61966.00,61967.00,61968.00,61969.00,61970.00,61971.00,61972.00,61973.00,61974.00,61975.00,0
61976.00,61977.00,61978.00,61979.00,61980.00,61981.00,61982.00,61983.00,61984.00,61985.00,61986.00,61987.00,0
61988.00,61989.00,61990.00,61991.00,61992.00,61993.00,61994.00,61995.00,61996.00,61997.00,61998.00,61999.00,0
62000.00,62001.00,62002.00,62003.00,62004.00,62005.00,62006.00,62007.00,62008.00,62009.00,62010.00,62011.00,0
62012.00,62013.00,62014.00,62015.00,62016.00,62017.00,62018.00,62019.00,62020.00,62021.00,62022.00,62023.00,0
62024.00,62025.00,62026.00,62027.00,62028.00,62029.00,62030.00,62031.00,62032.00,62033.00,62034.00,62035.00,0
62036.00,62037.00,62038.00,62039.00,62040.00,62041.00,62042.00,62043.00,62044.00,62045.00,62046.00,62047.00,0
62048.00,62049.00,62050.00,62051.00,62052.00,62053.00,62054.00,62055.00,62056.00,62057.00,62058.00,62059.00,0
62060.00,62061.00,62062.00,62063.00,62064.00,62065.00,62066.00,62067.00,62068.00,62069.00,62070.00,62071.00,0
62072.00,62073.00,62074.00,62075.00,62076.00,62077.00,62078.00,62079.00,62080.00,62081.00,62082.00,62083.00,0
62084.00,62085.00,62086.00,62087.00,62088.00,62089.00,62090.00,62091.00,62092.00,62093.00,62094.00,62095.00,0
62096.00,62097.00,62098.00,62099.00,62100.00,62101.00,62102.00,62103.00,62104.00,62105.00,62106.00,62107.00,0
62108.00,62109.00,62110.00,62111.00,62112.00,62113.00,62114.00,62115.00,62116.00,62117.00,62118.00,62119.00,0
62120.00,62121.00,62122.00,62123.00,62124.00,62125.00,62126.00,62127.00,62128.00,62129.00,62130.00,62131.00,0
62132.00,62133.00,62134.00,62135.00,62136.00,62137.00,62138.00,62139.00,62140.00,62141.00,62142.00,62143.00,0
62144.00,62145.00,62146.00,62147.00,62148.00,62149.00,62150.00,62151.00,62152.00,62153.00,62154.00,62155.00,0
62156.00,62157.00,62158.00,62159.00,62160.00,62161.00,62162.00,62163.00,62164.00,62165.00,62166.00,62167.00,0
62168.00,62169.00,62170.00,62171.00,62172.00,62173.00,62174.00,62175.00,62176.00,62177.00,62178.00,62179.00,0
62180.00,62181.00,62182.00,62183.00,62184.00,62185.00,62186.00,62187.00,62188.00,62189.00,62190.00,62191.00,0
62192.00,62193.00,62194.00,62195.00,62196.00,62197.00,62198.00,62199.00,62200.00,62201.00,62202.00,62203.00,0
62204.00,62205.00,62206.00,62207.00,62208.00,62209.00,62210.00,62211.00,62212.00,62213.00,62214.00,62215.00,0
62216.00,62217.00,62218.00,62219.00,62220.00,62221.00,62222.00,62223.00,62224.00,62225.00,62226.00,62227.00,0
62228.00,62229.00,62230.00,62231.00,62232.00,62233.00,62234.00,62235.00,62236.00,62237.00,62238.00,62239.00,0
62240.00,62241.00,62242.00,62243.00,62244.00,62245.00,62246.00,62247.00,62248.00,62249.00,62250.00,62251.00,0
62252.00,62253.00,62254.00,62255.00,62256.00,62257.00,62258.00,62259.00,62260.00,62261.00,62262.00,62263.00,0

Code:
returned value micros() _time==57
returned value micros() _time==56
PacketID: 38331
Length: 20
87 4D A2 3D C6 9D 61 29 59 DF D0 46 F0 62 AD 3E 13 73 96 6F 
returned value micros() _time==56
returned value micros() _time==57
PacketID: 45795
Length: 20
9E 72 7B 8C 1D 62 98 70 23 90 D8 70 EF D1 C8 A2 57 EF B8 54 
returned value micros() _time==56
returned value micros() _time==56
returned value micros() _time==57
PacketID: 61881
Length: 20
23 F9 49 C2 8C 8D CD F3 28 AB 66 5A D7 82 6B E1 D4 38 6B F5 
returned value micros() _time==57
returned value micros() _time==56
PacketID: 33759
Length: 20
B8 13 C4 2C 76 20 10 A0 A2 F9 E4 4C 91 A0 43 EF 3A 51 5A 69 
returned value micros() _time==56
returned value micros() _time==57
returned value micros() _time==56
PacketID: 15986
Length: 20
7D 1E 58 EA 97 2B F8 9F 3B 5E DF CC E1 FB E6 25 84 BA CA D5 
returned value micros() _time==57
returned value micros() _time==57
PacketID: 23039
Length: 20
19 B4 E4 1C D5 2B 9E F5 2F FE 91 8A DD 43 4F 45 62 1A 81 80 
returned value micros() _time==57
returned value micros() _time==56
returned value micros() _time==57
PacketID: 49191
Length: 20
2D 12 9B B2 DF 5F 8B 61 45 9C FE 45 DE 7A 38 15 DA ED E4 76 
returned value micros() _time==57
returned value micros() _time==56
PacketID: 26040
Length: 20
F9 15 45 28 C4 3A A5 3C 1C 11 58 88 BA 63 18 4B 85 5D 15 EC 
returned value micros() _time==57
returned value micros() _time==57
returned value micros() _time==57
PacketID: 59429
Length: 20
96 B9 5B 39 3C 62 31 15 EB D2 EC 33 8C C1 25 26 9E 57 C5 81 
returned value micros() _time==56
returned value micros() _time==61
PacketID: 24049
Length: 20
70 EC 87 9C 5D 4A F3 E9 5A 2F 5C 38 59 6B 14 F9 55 29 43 55 
returned value micros() _time==56
returned value micros() _time==56
returned value micros() _time==56
PacketID: 64829
Length: 20
86 B5 4D F5 AA 4A BA 28 29 29 28 FA 2C C2 48 96 DF DF 8A 35 
returned value micros() _time==57
returned value micros() _time==57
PacketID: 11167
Length: 20
68 C4 BB EC 6E ED D2 24 54 73 FC 70 73 37 5D DC 14 CC 4C 96 
returned value micros() _time==56
returned value micros() _time==57
returned value micros() _time==56
PacketID: 34381
Length: 20
9B 4E 66 77 A2 6A 61 A2 3C 9B 23 6B D2 F3 CD 43 E3 13 B0 8B 
returned value micros() _time==57
returned value micros() _time==57
PacketID: 4612
Length: 20
A5 BE 29 7C 95 8D B1 A9 19 F8 A9 D9 A7 F0 CB C9 F1 27 37 80 
returned value micros() _time==57
returned value micros() _time==56
returned value micros() _time==56
PacketID: 45878
Length: 20
E0 7F 6F 6B DF F1 B6 90 9D 5B E8 15 3D 11 9C 39 BF 6D 9E 3E 
returned value micros() _time==56
returned value micros() _time==57
PacketID: 59598
Length: 20
86 8A 11 64 9A 28 65 8D C6 2D 99 AA 67 2F 51 7B B8 2D FE AC 
returned value micros() _time==57
returned value micros() _time==56
returned value micros() _time==57
PacketID: 8595
Length: 20
6A 78 61 F2 85 C0 4E D7 85 49 E6 1A 54 75 F7 F5 3F C2 82 CE 
returned value micros() _time==57
returned value micros() _time==57
PacketID: 31968
Length: 20
8E C9 70 8B A0 C2 7E 85 C8 83 AB 63 8C F7 75 16 F2 1D D3 13 
returned value micros() _time==57
returned value micros() _time==57
returned value micros() _time==57
PacketID: 56467
Length: 20
AA 90 48 62 F4 7A 29 2B 80 9C B1 CC A6 20 AE D3 15 97 A6 C7 
returned value micros() _time==57
returned value micros() _time==56
PacketID: 18946
Length: 20
9B 32 6D 6F 5A D6 E2 FC 67 33 81 9A F0 A1 53 1C F1 38 2C EC 
returned value micros() _time==57
returned value micros() _time==56
returned value micros() _time==56
PacketID: 43631
Length: 20
41 25 3C FD 1B 85 75 FA C3 F7 94 23 5F B6 73 9B 5B 48 E7 96 
returned value micros() _time==56
returned value micros() _time==57
PacketID: 8090
Length: 20
8D BC 68 9D ED 92 89 A4 40 19 BD 31 2E 39 E2 92 A7 C4 9E 47 
returned value micros() _time==56
returned value micros() _time==57
returned value micros() _time==57
PacketID: 45976
Length: 20
F5 A3 54 49 15 7D B5 20 2B 68 23 9D 15 43 30 9F 66 35 68 28 
returned value micros() _time==59
returned value micros() _time==56
PacketID: 48082
Length: 20
EB F9 4E D1 9C 4A AD 6A EB 72 D7 F1 A9 9D 27 85 64 D6 E8 F5 
returned value micros() _time==57
returned value micros() _time==57
returned value micros() _time==57
PacketID: 64459
Length: 20
FE 68 1B 6D 9D 6B 92 7D BE 35 42 10 86 A6 6B 9A 8D 83 EC 25 
returned value micros() _time==57
returned value micros() _time==57
PacketID: 12978
Length: 20
CD 59 78 6D 5D 40 5E A4 B9 8A 86 D3 6B D8 18 D6 84 C2 5E D2 
returned value micros() _time==56
returned value micros() _time==59
returned value micros() _time==57
PacketID: 48062
Length: 20
A4 20 1D 50 D9 19 2B 35 67 CF 51 16 5D 73 F6 20 D1 AD 19 CD 
returned value micros() _time==57
returned value micros() _time==57
PacketID: 57864
Length: 20
A1 B3 B7 51 80 69 73 5E DD 24 1F 70 85 77 43 F9 AC E7 14 3C 
returned value micros() _time==56
returned value micros() _time==57
returned value micros() _time==56
PacketID: 62471
Length: 20
E1 ED F3 DF B1 E9 90 52 BD 11 BD DF C1 16 27 D7 49 7A DF F9 
returned value micros() _time==56
returned value micros() _time==56
PacketID: 44759
Length: 20
2B 15 D4 3F 76 48 9C 13 90 11 C8 29 57 85 14 AC DD 7A 43 67 
returned value micros() _time==57
returned value micros() _time==57
returned value micros() _time==56
PacketID: 30607
Length: 20
D3 57 9B BC 9B C1 5C 9A 60 12 6F F1 3F 93 33 B7 18 8F C7 F2 
returned value micros() _time==57
returned value micros() _time==57
PacketID: 11163
Length: 20
9E BD CA 60 71 51 22 E5 68 99 E4 99 3C 3D FC 26 D6 B5 68 70 
returned value micros() _time==57
returned value micros() _time==57
returned value micros() _time==56
PacketID: 44730
Length: 20
FD 18 E4 2D 2F 31 80 26 3D 8C 56 56 BD F6 C9 68 7F DF 47 F0 
returned value micros() _time==56
returned value micros() _time==56
PacketID: 6328
Length: 20
D5 28 7C A0 F5 C5 18 11 D9 6E 8D 8C A6 CB B7 BD 98 10 A5 52 
returned value micros() _time==57
returned value micros() _time==57
returned value micros() _time==57
PacketID: 17986
Length: 20
91 CC F4 9D B7 8B 78 5F 30 F6 B5 77 30 59 A2 7E 73 B1 63 AE 
returned value micros() _time==56
returned value micros() _time==56
PacketID: 10560
Length: 20
86 BF 6D 1C FC 6B 9A 93 D4 AE B5 79 68 7D 52 97 82 76 CE B5 
returned value micros() _time==57
returned value micros() _time==56
returned value micros() _time==57
PacketID: 9764
Length: 20
5D 55 E8 E9 4E A7 8A 17 A7 61 DC 64 8E B7 4E 51 FC DB 56 F2 
returned value micros() _time==56
returned value micros() _time==57
PacketID: 4834
Length: 20
F7 CB BA 8B 16 24 94 C6 29 4A EC 52 B9 EF 95 6F 17 DE 59 AE 
returned value micros() _time==57
returned value micros() _time==57
returned value micros() _time==56
PacketID: 64485
Length: 20
8D CF 4E A9 24 DA 94 1F 42 33 6D F0 FE A2 2A D6 27 FA 5A 3F 
returned value micros() _time==57
returned value micros() _time==57
PacketID: 52473
Length: 20
40 FE 9D 3F 16 FB 37 9F 25 6E 47 4A C3 6A 2B B1 9E 11 22 53 
returned value micros() _time==57
returned value micros() _time==57
returned value micros() _time==56
PacketID: 20862
Length: 20
52 81 E4 F7 35 F0 11 85 E9 DE 9F 4E 99 D1 80 81 AA 3B F2 14 
returned value micros() _time==57
returned value micros() _time==57
PacketID: 2926
Length: 20
76 24 D3 DA A6 82 5C C4 18 BA C7 7E 93 32 E1 E3 D1 EF A1 73 
returned value micros() _time==57
returned value micros() _time==57
returned value micros() _time==57
PacketID: 47243
Length: 20
FE 13 1D A6 4C 6B 43 58 9F 47 C4 E1 A3 B1 28 6E 28 20 A2 3A 
returned value micros() _time==61
returned value micros() _time==60
PacketID: 46185
Length: 20
20 A8 48 E3 C9 2E B8 9C F6 21 2E 79 F5 A7 70 52 3B 7B E2 C7 
returned value micros() _time==56
returned value micros() _time==57
returned value micros() _time==57
PacketID: 57338
Length: 20
26 ED 34 3B 11 D1 3E 77 B2 D3 B9 A0 4D 31 B2 A2 62 EF C5 3C 
returned value micros() _time==56
returned value micros() _time==57
PacketID: 43372
Length: 20
9D C8 E5 CE 57 42 69 C9 69 96 BF ED 6A 4E C0 D0 89 59 D0 F0 
returned value micros() _time==57
returned value micros() _time==57
returned value micros() _time==56
PacketID: 3745
Length: 20
37 55 89 B2 65 9B FE 48 6C 72 35 F3 46 7A 87 6E B5 DF C8 95 
returned value micros() _time==56

EDIT, just got ONE error but still going
 
Im thinking the error could be at the master->slave end as well when it's getting dequeued from loop while isr refires, so i put this in the slave events:

Code:
    __disable_irq();
      auto _deque = move(teensy_handler_queue.front());
      teensy_handler_queue.pop_front();
    spi0_isr();
    __enable_irq();
    NVIC_SET_PRIORITY(IRQ_SPI0, 0); // set priority
    NVIC_ENABLE_IRQ(IRQ_SPI0); // enable CS IRQ

now lets wait and see
 
touching the master -> slave one caused lockups after a while, so i reverted those changes and trying something else for slave->master:

Code:
    __disable_irq();
    teensy_stm_queue.push_back(_vector);
    if ( !(GPIOD_PDIR & 0x01) ) spi0_isr();
    __enable_irq();
    NVIC_SET_PRIORITY(IRQ_SPI0, 1); // set priority
    NVIC_ENABLE_IRQ(IRQ_SPI0); // enable CS IRQ

now it checks for pin low state before firing spi0_isr and then enables interrupts, letting it run

note: this is with these in master loop() without millis delays, so i flood as much as possible, but it's keeping up at 0 errors. T3.5S120, T3.6M180,30mhz
Code:
teensy_gpio.digitalWrite(13, !teensy_gpio.digitalRead(13));
teensy_gpio.events();

edit1: 1 error after 5 minutes
 
this one runs the longest without errors


Code:
uint16_t SPI_MSTransfer::transfer16(uint16_t *buffer, uint16_t length, uint16_t packetID, bool fire_and_forget) {
  if ( _slave_access ) {
    uint16_t data[6 + length], checksum = 0, data_pos = 0;
    data[data_pos] = 0xAA55; checksum ^= data[data_pos]; data_pos++; // HEADER
    data[data_pos] = sizeof(data) / 2; checksum ^= data[data_pos]; data_pos++; // DATA SIZE
    data[data_pos] = 0x0000; checksum ^= data[data_pos]; data_pos++; // SUB SWITCH STATEMENT
    data[data_pos] = length; checksum ^= data[data_pos]; data_pos++;
    data[data_pos] = packetID; checksum ^= data[data_pos]; data_pos++;
    for ( uint16_t i = 0; i < length; i++ ) { data[data_pos] = buffer[i]; checksum ^= data[data_pos]; data_pos++; }
    data[data_pos] = checksum;
    std::vector<uint16_t> _vector(data, data + data[1]);
    __disable_irq();
    teensy_stm_queue.push_back(_vector);
    if ( !(GPIOD_PDIR & 0x01) ) {
      spi0_isr();
      __enable_irq(); 
      NVIC_SET_PRIORITY(IRQ_SPI0, 1); // set priority
      NVIC_ENABLE_IRQ(IRQ_SPI0); // enable CS IRQ
    }
    else {
      __enable_irq(); 
      NVIC_SET_PRIORITY(IRQ_SPI0, 1); // set priority
      NVIC_ENABLE_IRQ(IRQ_SPI0); // enable CS IRQ
    }
    return packetID;
  }

you'll have to patch another section in the spi0_isr if we call it manually:

Code:
    /* BEGIN PROCESSING */


    while ( 1 ) { // wait here until MASTER confirms ACK receipt

to:

Code:
    /* BEGIN PROCESSING */


    while ( !(GPIOD_PDIR & 0x01) ) { // wait here until MASTER confirms ACK receipt

doing this with above T16 patch and more than 10 minutes no errors

heres my patched files for testing

View attachment testing.zip
 
yup, after awhile it does end up locking, but at least its more proof its a queue pop/push issue :) aparently the STL queues use malloc, which is never safe in an isr according to articles online
 
any ideas for exporting the buffer contents than?

im wondering how fast those vector swaps are
perhaps we add a secondary queue just for the ->master transfer, and if the slave detects during loop() time that the queue is empty, it does a swap on the queue which actually doesnt move/copy, it just swaps the pointers of the arrays so the other end would be full and the local one empty
 
Static Buffers with Active/Used flag tracking in some fashion.

The Microcontroller world is like my old job . . . raw "C" only.
 
you mean a static array to store the buffer, and after ISR, to queue it? how can you get it queued fast enough before next loop iteration before ISR fires again to overwrite it's contents? lots of hoop testing here :)
 
"Can't" sounds sort of negative - when anything is possible :) ... It is a paired system - set constraints and limits as appropriate. Max message size - multi part if needed.
 
now im trying with volatile bool _stm_queue_busy = 0;

1) for the transfer16 on slave i set _stm_queue_busy to 1.
2) in the ISR, if the value is 0 and the queue exists, THEN read the front of the queue, but DONT DEQUE (commented out)
3) in events, if _stm_queue_busy is set, POP the front queue and THEN unset _stm_queue_busy.


ONLY events can UNSET the bool
ISR & T16 can ONLY SET it
ISR ignores transfers if set
so far its working! (the POP is done from EVENTS, NOT ISR)
 
im using 2 flags now actually
one for events() to DEQUE with ISR flag, and a flag for T16, telling ISR to not transfer any data while it's queing up another queue

im slamming 50ms slave loops now for transfers -> master



View attachment booltest_2.zip

this needs testing but i think it works!?

unless loop() wipes out the flag, all further ISR transfers wont happen until loop wipes flag AFTER POPPING the queue (that was already transfered)

this does NOT stop the slave from queuing up more data!

test this pls! :D

so for the QUEUE system for the SLAVE -> MASTER now ONLY THE MAIN LOOP HAS ACCESS TO POP&PUSH (NOT ISR)

:)
 
reference modification points for slave -> master:

::transfer16 method

Code:
uint16_t SPI_MSTransfer::transfer16(uint16_t *buffer, uint16_t length, uint16_t packetID, bool fire_and_forget) {
  if ( _slave_access ) {
    [B][COLOR="#FF0000"]_stm_queue_busy = 1;[/COLOR][/B]
    uint16_t data[6 + length], checksum = 0, data_pos = 0;
    data[data_pos] = 0xAA55; checksum ^= data[data_pos]; data_pos++; // HEADER
    data[data_pos] = sizeof(data) / 2; checksum ^= data[data_pos]; data_pos++; // DATA SIZE
    data[data_pos] = 0x0000; checksum ^= data[data_pos]; data_pos++; // SUB SWITCH STATEMENT
    data[data_pos] = length; checksum ^= data[data_pos]; data_pos++;
    data[data_pos] = packetID; checksum ^= data[data_pos]; data_pos++;
    for ( uint16_t i = 0; i < length; i++ ) { data[data_pos] = buffer[i]; checksum ^= data[data_pos]; data_pos++; }
    data[data_pos] = checksum;
    std::vector<uint16_t> _vector(data, data + data[1]);
    teensy_stm_queue.push_back(_vector);
  [B][COLOR="#FF0000"]  _stm_queue_busy = 0;[/COLOR][/B]
    return packetID;
  }

ISR:

Code:
                if ( [B][COLOR="#FF0000"]!_stm_queue_delete && !_stm_queue_busy &&[/COLOR][/B] !_slave_pointer->SPI_MSTransfer::teensy_stm_queue.empty() ) { // IF QUEUES EXIST, ONE WILL BE DEQUEUED TO MASTER
                  [B][COLOR="#FF0000"]_stm_queue_delete = 1;[/COLOR][/B]
                   [B][COLOR="#FF0000"]// 2 lines deleted (queue move & deque)[/COLOR][/B]
                  uint16_t checksum = 0, _deque_pos = 0;
                  while ( !(GPIOD_PDIR & 0x01) ) {
                    if ( SPI0_SR & 0xF0 ) {
                      SPI0_PUSHR_SLAVE = [B][COLOR="#FF0000"]_slave_pointer->SPI_MSTransfer::teensy_stm_queue.front()[/COLOR][/B][ ( _deque_pos > [B][COLOR="#FF0000"]_slave_pointer->SPI_MSTransfer::teensy_stm_queue.front()[/COLOR][/B][1] ) ? _deque_pos = 0 : _deque_pos++];
                      if ( SPI0_POPR == 0xD0D0 ) { SPI0_SR |= SPI_SR_RFDF; return; }
                    }
                  }
                  SPI0_SR |= SPI_SR_RFDF; return;
                }

events()
Code:
  if ( _slave_access ) {
[B][COLOR="#FF0000"]    if ( _stm_queue_delete ) {
      _slave_pointer->SPI_MSTransfer::teensy_stm_queue.pop_front();
      _stm_queue_delete = 0;
    }[/COLOR][/B]

as i typed all this, its still pounding at 50ms rates and 0 errors!
 
Cool.

Maybe go ahead and release an complete V_0.2.1? - I don't see the define of _stm_queue_bus or _stm_queue_delete. I'll try it out - but don't want to get stuck on my poor editing. You can edit the base Master and Slave ino for new Examples if you want for testing - or add a "StoM" version? I'm going to port the existing examples to "TV_" for TViewer usage on 'other' thread to assure those are clean and working and easy to track.
 
same examples, just now i replaced volatile with std::atomic bool instead, because "a volatile variable does not guarentee enforcing any memory barriers nor any cache mechanism"

been reading up online and std::atomic seems to be well defined and better to use than volatile

Code:
std::atomic<bool>_stm_queue_busy;
std::atomic<bool>_stm_queue_delete;

View attachment SPI_MSTransfer 0_1_2.zip

Changed volatiles to c++ atomics
 
Usually. I ran into a problem with going back and forth between atomic's and non-atomic's. For instance I couldn't get an atomic to print with serial.print so I had to assign it to a non-atomic. Forgot the exact syntax I was using but that one I remember. Figured I would just mention it, just in case :)

EDIT> Running it now. Still won't do 120/120 but 168/120 works. So far so go. Have 1 OT but that was on start up.
EDIT1> Test conditions - master loop at 20ms and slave loop for transmit at 20ms.
 
Back
Top