Code Monkey home page Code Monkey logo

Comments (8)

cnlohr avatar cnlohr commented on May 22, 2024

You don't need to stop interrupts if you are in one. cli/sei aren't a single instruction but they are probably better to be __disable_irq / __enable_irq.

You would need to show me more code if you are struggling to get info on how to improve your interrupt code.

from ch32v003fun.

phantomxe avatar phantomxe commented on May 22, 2024

PD3 with rising edge trigger used in pin change example code;

// Configure the IO as an interrupt.
AFIO->EXTICR = 3<<(3*2); //PORTD.3 (3 out front says PORTD, 3 in back says 3)
EXTI->INTENR = 1<<3; // Enable EXT3
EXTI->RTENR = 1<<3;  // Rising edge trigger

// enable interrupt
NVIC_EnableIRQ( EXTI7_0_IRQn );

I'm try to write both rising and falling trigger for pc1.

AFIO->EXTICR = 2<<(1*2);  
EXTI->INTENR = 1<<3; 
EXTI->RTENR = 1<<3;  
EXTI->FTENR = 1<<3;  

Is it correct?

EDIT: It's wrong.

AFIO->EXTICR = 2<<(1*2); // PC1: PortC = 2, << Pin1 = 1 * 2 
EXTI->INTENR = 1<<(1); // EXT1 Enable
EXTI->RTENR  = 1<<(1); // EXT1 Rising edge trigger
EXTI->FTENR  = 1<<(1); // EXT1 Falling edge trigger

It worked now.

from ch32v003fun.

cnlohr avatar cnlohr commented on May 22, 2024

I believe that is also correct, generally.

from ch32v003fun.

phantomxe avatar phantomxe commented on May 22, 2024

I made a little progress. https://github.com/phantomxe/ch32v003_ow/tree/main/ow_probe_adc

Also combined with ADC DMA example. But i got some triggering problems at reset state. Is it possible to check my code in terms of interrupt usage or general structure? @cnlohr

from ch32v003fun.

cnlohr avatar cnlohr commented on May 22, 2024

I am not quite sure what I should be searching for.

One thing makes me anxious is the EXTI7_0_IRQHandler interrupt - You should probably use a state machine, either with a switch statement or a function pointer to the current state, It will prevent a lot of branches. Branches on the CH32V003 are expensive.

from ch32v003fun.

cnlohr avatar cnlohr commented on May 22, 2024

I am still interested in seeing this come to fruition. Any chance you would still get it further over the finish line?

from ch32v003fun.

cw2 avatar cw2 commented on May 22, 2024

I apologize in advance for hijacking this thread with potentially irrelevant information, but if I remember it correctly it is not possible to emulate the 1-wire protocol in a slave device unless you have a proper Maxim/Dallas license (or use genuine Maxim/Dallas part). Unfortunately, I could not find the original document with the information, only informal mentions on the internet. IANAL so it might be fine to use 1-wire slave device emulation for e.g. educational purposes, but if you plan to use it commercially, I would recommend checking with the company legal department.

Sorry again and thank you for your understanding.

from ch32v003fun.

phantomxe avatar phantomxe commented on May 22, 2024

@cw2 Thanks for your attention. I just on the educational zone.
@cnlohr I used to think that I had a knowledge about development on embedded systems. But after i started with experimenting on ch32v003fun, i found my knowledge is mediocre. After several weeks of development with logic analyzer, It worked partially. It can sense the reset and respond with presence pulse, read-write operations are possible. I want to combine with adc dma example. I tried to send ADC data over scratchpad but it's not working.

//so I'm not going to do temperature conversion at now 
scratchpad[0] = (uint8_t)(adc_buffer[0] & 0xFF); // FIXME not working
scratchpad[1] = (uint8_t)((adc_buffer[0] >> 8) & 0xFF);   
scratchpad[2] = 0x31; // for debugging

And i refactored if-else statements to switch-case. You can have a look at my latest code in the repository. But I don't understand that why i can't run any printf, adc on main loop when onewire stuff is working on interrupt. Sorry for the inconvenience.

from ch32v003fun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.